Jump to content

Constrain object movement to mesh during mouse drag


Recommended Posts

HI - sure appreciate a hand in figuring out how to constrain an object's movement during mouse drag.

I'm trying to get the sphere to follow the contour of planes as I drag it across the flat and up the ramp (and vice-versa) - see photos below...

Currently it doesn't work in this playground - the sphere drags right through the ramp.

Here's the code in the playground - https://www.babylonjs-playground.com/#9UFEBE#15

If better to create a single mesh rather than two intersecting meshes, please let me know.

Many thanks ?







Link to comment
Share on other sites

First what I see that is check putted in onStart event, so this check doest not calling when you dragging. 
If you want to check y coordinate while dragging, you should put this y-check in the onDragObservable, but it will rude.

Here is the old topic, when you can see example of limiting movement in XoZ plane, but it uses not behaviour, it implementing behaviour via pointer events, for now you can change all this to:
OnPointerObservable http://doc.babylonjs.com/api/classes/babylon.scene#onpointerobservable because it is newer and better, but the core problem for now I have no idea how to clearly and perfectly make solution for your problem. Thinking on it.


Link to comment
Share on other sites

Wow, this thread got active!  COOL!


I'm working on a physics-active version.  :)

PointerDragBehavior in line 87... needed 'None' parameters ( see http://doc.babylonjs.com/how_to/meshbehavior#pointerdragbehavior )

There's some "debris" in there.  I tried a now-famous technique of dragging a physics-active invisible isphere, placed directly atop the visible sphere, with the two mesh/impostors connected by a non-colliding physics joint.  That didn't work so well. 

Here's a "jointed-mover" demo, as wanted.  https://www.babylonjs-playground.com/#15AFCG#30
The arrow keys move the little box.  The little box is attached-to the green box... with a physics joint.  The joint "soft-positions" the green box.  The firm-rubber-like joint between the little box and the green box... causes the softening.  It allows some physics engine "stretch" and "flex".  Without it, an arrow key can cause a very high velocity physics collision, which can cause a collided mesh to fly-off, violently.

Just the same, I am allowing dragBehavior to "force-position" the physicsImpostor for sphere (with no joint/link-to an invisible mesh).  Dragging the sphere into a collision with another physics-active mesh... COULD be radical (high rebound power due-to possible high linear-velocity of drag-move).

So far, I'm only doing collisions with ramps.  Works sort-of OK.

It's not always wise to force-move physics impostors.  Physics impostors prefer to be in-charge of positions & rotations... to make the mesh act physics-real.  *shrug*

Surely, more comments soon.  Stay tuned.

Link to comment
Share on other sites

Hi Wingnut - really appreciate the education on imposters. I tweaked my playground a bit more - it's close to the functionality I need use dragPlane - as you can see, the sphere stays within the ground plane when dragged. Unfortunately what it doesn't do is go up the ramp when dragged onto that plane - any thoughts on that? I played with a number of different constraints and none produced the right result. 

Is it possible to create a single mesh and with a flat and a ramp and have the sphere follow that?



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.

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.


  • Recently Browsing   0 members

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