I am trying to use the LockConstraint to lock to “glue” 2 objects together. In all the demos I saw, the pivot point was chosen arbitrarily, which caused the 2 objects to be moved in order to satisfy the constraint, hence not acting like a glue but more like a magnet between 2 points.
Instead, I would like to create a LockConstraint that is satisfied given the initial relative positions of my 2 objects, gluing them in place relative to each other.
I defined the pivot point as being the average position of the 2 objects, and then transform this position in the local space of the 2 objects to create the constraint but I can’t make it work unfortunately:
Thanks that’s better! But I am not sure how I can account for object rotation if I don’t use an inverse world matrix somewhere
If I understand correctly, the pivotA is the position of bodyA in local space of bodyB and and pivotB is the position of bodyB in local space of bodyA ? x)
correct! if you want to set world space anchor position, then yes, you’ll need to use parent inv matrix. I’m a bit biased as I always set values from local.
Ah I see the issue in my first playground was not calling computeWorldMatrix(true) before computing the inverse!
I tried using the same method for the constraint axis but I did not get the expected result:
I think the problem is that I do not really understand what the axis should be for a LockConstraint. For a hinge it is quite intuitive that the axis is the axis of the hinge itself in the local space of both objects, but here I really have a hard time understanding that
And then when I enable the constraint I expect to get the same result, but instead depending on the axis I choose I get this (both axis are transformed with the inverse world matrix):