Hi, I have a character whose bones I want to rotate between two other entities.
For example, in the image provided, there are two cubes, one is fixed on the shoulder and the other(the one on the elbow) is controlled by the player in 3 dimensions. I want the characters arm to rotate according to the player controlled cube.
You may have a NaN in your calculations which can screw up the transformation matrix.
For the problem, I generally create a rotation matrix and either do a lookAt (if the local forward axis of the shoulder node is down the arm) or rebuild the matrix with up/right/forward vectors depending on the local axes of the shoulder.
Thanks for the reply, actually the calculations were correct but it became NaN after I did setRotation(). Changing setRotation to setEulerAngles stopped the arm from disappearing but now it’s moving in unexpected ways. I even tried the following but it still moves unexpectedly:
quat = new pc.Quat();
quat.setFromEulerAngles(ax2, ay2, az2);
ybot.findByName('mixamorig:LeftArm').setRotation(quat);
Example: ( The character’s arm should be horizontal)
Oh yes, setRotation expects a pc.Quat, not euler angles.
Without spending so time digging into this, the XYZ axes on shoulder joint may be different to what you are expecting . eg the forward axis of the shoulder may not be going down the arm
Also, negative Z is forward in PlayCanvas (it looks like the elbow is pointing in the opposite direction to where it should be?) so that could be an issue?