Jump to content

Rotate meshes when collision with other mesh


vahith
 Share

Recommended Posts

Hi guys...  I've been playing: http://www.babylonjs-playground.com/#LGY91#2

 

click is still active, and so is drag... but this one starts moving automatically.  click (or drag) the box and it picks a random direction of four... and starts moving again.  Box stops when it impacts a wall (even though a continuous move is still happening).  Console msg on impacts.

 

I just expanded Luaacro's idea, which is a good idea.  In the line 180 area... I added 3 more registered actions (total of 4, now), so there is a trigger->action function for all 4 walls.

 

I'm not doing any rotation adjusting (yet).  I just wanted to get 4 different collision functions, and then Vahith can play-with rotations.  He can check his box "purple-side", get it aimed correctly, and then do more, with these 4 "impact functions".

 

There may be problems, Vahith.  What happens if you move into a corner, so two different intersects are happening at the same time?  Might be a problem.  They might keep interrupting each others' actions.  *shrug*

 

Also, the box MIGHT "struggle" to rotate because collision events might be happening WHILE you are doing a "slow rotation".  I don't know IF you are planning a slow rotation, or an "instant rotate".  Instant rotate, no problems. 

 

Slow rotate, maybe too many collision events with a wall... during rotate.  Might be "jumpy".

 

So, IF you do slow rotation, then maybe UN-register the action for the wall that the box is touching, THEN rotate, then re-register the action for that wall.

 

Or, there might be a cheat way.  Maybe "collapse" the box.ellipsoid to (0,0,0) size, THEN rotate the box, THEN repair/reset the correct box.ellipsoid again.  By collapsing the ellipsoid, the collisions should stop.  BUT... this demo has  moveWithCollision inside the animation loop... so... collapsing the box.ellipsoid COULD make the box move thru the wall and into outer space.  :)

 

So... hehe... you might want to set way = BABYLON.Vector3.Zero();  (maybe IMMEDIATELY when an impact happens).

 

That doesn't stop the moveWithCollsions, but it makes it continuously move "here".  :)

 

After that, collapse the ellipsoid (the box should stay positioned), place a proper animated rotation function on the registerBeforeRenderLoop, and wait for it to complete.  Once complete, put the ellipsoid back to normal, and maybe start a new move or wait for a user click.  *shrug*

 

Issues issues issues.  :)

 

Maybe there is some useful "steering" code in Wingy's World's-Worst Flight Sim.  And maybe not.

 

In this forum post, Temechon showed me "something".  (ignore "applyImpulse", that's a physics engine thruster).  The important part would be v2... which is possibly a "forward" vector.  (I should learn this stuff someday.  Directional vectors and magnitudes... kind of suck.  I don't do directions well.)  ;)

 

All in all, I think there is steering happening to v2.  I have heard of people "calculating an UP vector" and a "forward vector"... so forum searches might be helpful.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...