ewanvalentine

How would I go about moving a mesh using physics from its original point, to a picked point?

Recommended Posts

Hi folks,

I have the following example...

http://www.babylonjs-playground.com/#OYE6Q#4

I was wondering how I'd go about moving the smaller mesh around the plane, by clicking on it, then clicking on a different point in the plane, but in such a way that it uses the physics engine. Currently, if I set another block to having 0 mass, so that it's static. The smaller moveable block passes through the static block. 

I understand that this is because, animation doesn't actually use the physics engine. So I was wondering if anyone knew how to replicate this behaviour, but using the physics engine. 

I attempted to use 'applyImpulse' but that seemed to be for applying constant force, such as onKeyDown.

I'm a total n00b to game dev and to Babylon, so any help is hugely appreciated. 

Cheers,

Ewan

Share this post


Link to post
Share on other sites

Hi i-man!

    I have no solutions but I made a playground of it... http://babylonjs-playground.azurewebsites.net/#1NQTNE .  That makes it easy for folks to experiment and/or grab a home zip, and play along.  I also turned-off shadows, temporarily.

 

Yeah, you have a fun world of ramps and jumps started here.  WASD to drive around, but I don't think A/D are coded-up, yet.  It's 3:30 AM here, and I just barely got the playground version operational.  There is some drool on my keyboard, so I assume I am tired.  :)

 

These picking rays are fun.  I know very little about them, but iiceman has found an interesting use, here.  It seems that they NEARLY allow us to watch the collision ellipse interact with environment... live, in real time.  Handy!  Interesting!  I'm going to study this... tomorrow.  :) 

 

Besides, the experts on moveWithCollision will be waking soon.  It's best that I'm not in their way.  :)

Share this post


Link to post
Share on other sites

@ViBe Your example is EXACTLY what I was attempting to do! I went through the thread you linked me to, but I'm still confused. That thread seems to suggest using `mesh.position` which is ignored by the physics engine. So when I attempt to use a few of those suggestions, I still run into the problem whereby my mesh passes through static meshes, instead of moving around them such as your example. Hope this makes sense. I'm attempting to create something similar to Red Alert in terms of movements and physics.

Share this post


Link to post
Share on other sites

There is a misunderstanding here:

- moveWithCollisions is used with the collision engine which uses ellipsoid vs. mesh type of collisions (other objects must have checkCollisions = true)

- If you want to use physics then you have to set impostors and call applyImpulse to move an object

Share this post


Link to post
Share on other sites
34 minutes ago, Deltakosh said:

If you want to use physics then you have to set impostors and call applyImpulse to move an object

Yep, yep, yep.  And if I may expand on this... it is not easy to stop a moving mesh (rigged with a ghostly physicsImpostor)... at an exact clicked point.

But I know a little secret.  :)  Okay, okay, it's not a secret, it's just an idea.  What if... you put an invisible object at the clicked place.  Now... umm... not sure if it is possible, but use a Babylon Ray to shoot at the about-to-move mesh (FROM the invisible mesh) .  From that ray hit, calculate the direction vector that the mesh impostor would need to use... to get-to the location of the invisible click-point.  Then apply an impulse/linearVelocity to the mesh... and it will start moving toward the clicked point.

Then do it all over again, over and over, tiny impulses/linearVelocities... until the distance between the clicked point and the impostor'd mesh... is low/none.  Then, force the impostor into sleep mode or set all angularVelocity and linearVelocity to zero.  In a way, you have created a mesh magnet, right?  The invisible mesh at the click location... is sending instructions to the mesh impostor... telling it how to impulse itself to the clicked point.  :)  I don't know if it would work, but I sure am curious to know.  :)

It's similar to when someone calls you at home, from their car... and you "talk them in", telling them how to find your house.  :)

This is for the physics engine system, and NOT for checkCollisions, mesh.ellipsoids, moveWithCollision,etc. (Not for built-into BJS collision system, which doesn't use linearVelocity/applyImpulse, physicsImpostors, restitution, friction, mass).  The only thing that is common between these two separate systems... is scene.gravity (and that can be superseded by a settable gravity specifically on the physics engines)

Share this post


Link to post
Share on other sites
6 hours ago, ViBe said:

@ewanvalentine To start it is not my work (just a topic I have read and found relevant).

 

If you affect on your building the checkCollisions property to true, it seems to work :


	building.checkCollisions = true;

http://www.babylonjs-playground.com/#OYE6Q#9

Ahhh great spot! Perfect! Thanks everyone else, I'll look into your suggestions as well. You've all been a big help :)

Cheers,

Ewan

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.