Please help me, making precise mouse dragging for Havok physics meshes

I want to drag meshes that are physics enabled, but I want to grab and move them on the exact area I pulled like so;

ISSUE: this works by making a joint on the raycast area and the object. this works pretty well BUT I cant throw the object because the dragger is pretty digital in its input.

The solution would be to use a Spring joint, but they don’t exist in physics v2 so the next best thing would be to simulate a spring using ApplyForce like this;

But the new issue with this is that I lose the exact area I clicked on and have to apply the force to the centre of the box.

My idea to counteract this was to make another body like an anchor that gets a lock joint to the mesh then use the apply force method to the small anchor point.
No idea why, this makes everything jitter, heavy and doesn’t work the way I want (Please note, PG uses a set anchor point for testing, doesn’t read mouse ray)

I am at my wits end trying to make this work, I am not sure where to go here, if the applyforce method could effect recast hit areas or if I can use the joint method but have it retain velocity so I can throw objects around.

Thanks for the help in advance!

Just to help clarify my issue, I like the precision of the first PG but want the feeling / movement of the second PG. the last PG was my attempt to combine them but just causes havok to freak out.

cc @carolhmj and @Cedric

I’ll look at it ASAP :slight_smile:

1 Like

Hmm I started experimenting with some ideas, but haven’t got anything very satisfying yet. Looking back at this thread however which also involves the movement of a constrained system Havok physics behaves unnatural when moving a box with a constraint - Questions - Babylon.js (babylonjs.com), it has some good information that can be applied here. Have you looked into updating the anchor’s velocity instead of its position?

@jamessimo I’m using the exact same interaction in my app https://www.mokk.app/

You’re basically almost there, the only thing you’ll need to change: instead of moving the sphere directly by setting the position (which I assume is what the PointerDragBehaviour is doing) you need to apply an appropriate force to move it. The last playground in @carolhmj’s post has example code for this: Havok physics behaves unnatural when moving a box with a constraint - #13 by carolhmj (check the setPosition function)

I’m not sure if you can stop PointerDragBehaviour to modify the position of the sphere direclty. In case it’s not possible you can either use another sphere for the actual joint or implement your own pointer drag behaviour (this is what I did, don’t really recommend it for this case :sweat_smile: I think I did it because I wanted to have more control for some other parts).

1 Like

Thank you for the info.

I didn’t do it the way you said only because I really wanted to lean in on built-in Babylon functions I e the drag function.

I still use the pointer drag behavior on a NON-physics sphere but then use the physics anchor to move to use its XY to move the anchor to it like in my 3rd example.

I ended up just using some angular and velocity drags to help smooth out the interactions and some code cleanups. it works MUCH BETTER now!

Another strange thing is that the Sphere (mouseBall) naturally lerps to the mouse XY and is not instant. Not sure what’s causing this but now the feeling is much better.

It’s #7 on the last play ground I shared if you want to see. Much better now. I am porting this over to my project and adding some other nice-a-tees.