Havok set joints positions on Raycast

Hey guys, I have a demo here and have 2 problems

Problem 1)
When you click the box and it will attach the sphere to it via a ball and socket joint.

This works BUT as you can see the joints local origin is hard coded. I am not sure how to take the Raycast hit (green ball) and set the joints origin to be the same. (When you attach a joint you will have to re-click the little grey ball to drag it. What i want to do is click on say a corner or the center of a face then the grey little ball will be attached there.

Problem 2)
Is there a way I can tell the sphere end of the joint to be automatically clicked and active in its drag state? Right now I have to click once to attach and click again to drag it.

Hello,

You need to get the hit position of the raycast, which is expressed in world coordinates, and convert it to each body’s local coordinates, i.e, relative to their origin.

Is there a way I can tell the sphere end of the joint to be automatically clicked and active in its drag state? Right now I have to click once to attach and click again to drag it.

I’m not sure what you mean by “clicked and active” here?

Is there a helper function to convert it to each body’s local coordinates. I cant find any easy way on Babylon.

So in my example. I click on the mesh and the sphere I want to drag gets snapped into the worldspace but its not in the “drag” state because I didn’t give it a pointer down. I want to programatically set it to “active” or “dragging” state.

There’s nothing built in but you can just transform the world coordinates by the inverse of the body’s world matrix. The begining of these two videos have a very good explanation on coordinate systems transformations: Camera/View Space // OpenGL Beginners Series - YouTube
3D Software Rendering Graphics Pipeline - YouTube

About the PointerDragBehavior, you can simulate drag using the start and releaseDrag methods: PointerDragBehavior | Babylon.js Documentation (babylonjs.com)

So I think I’m doing it right but I don’t understand what axis A and Axis B need in the BallAndSocketJoint

I am subtracting the vector by the world matrix but it only works on one plane it feels like, I assume rotation may be needed too?

Constraints | Babylon.js Documentation (babylonjs.com)
About Axis A and Axis B on all the constraints, they’re used to define the reference coordinate system along where the objects will move. The axis you pass doesn’t affect much the BallAndSocket constraint because it’s free to rotate on all axes, but it would make a difference in a Hinge constraint where it can’t rotate along all axes.

You can use the TransformCoordinates function of the Vector3 class and then use the inverted world matrix to convert from world space to local space

1 Like

Thank you so much!