I have worked out how to code a ray from the camera to the floor in 3D space and then find the rotation for a mesh to point towards the camera.
I have an animation tree and animation player that allows me to transition between animations. The animation transitions from idle to moving when you move the player around the screen. This involves rotating the player backwards.
I found a set_bone_rot script in the docs and it looks to me like you choose by which direction it applies the rotation in like:
Vector3(1, 0, 0), vector3(0, 1, 0), vector3(0, 0, 1)
This seems to work when I've uncommented the 'var new_pose' and replaced the 'var's so that it doesn't try to redeclare the same variable. So it seems that this applies the rotation through each axis.
This seems to work, as expected. But something I've tried to do is use the same code I've found online that points a mesh to the mouse (but instead set the top spine bone rotation to point to that).
This works, except, there seems to be issues like when you stop walking the top spine bone rotates towards the mouse with an offset. I have not worked out what causes this offset yet. Is it maybe to do with animation blending?
I am also having trouble getting the amount that the state machine has transitioned. I tried setting 'parameters/moving/blend_position' in the animation tree and haven't found the correct parameter.
So how can I garantee that the bone looks like it is pointing to the exact same point?
At the moment I just have it coded to rotate the top bone to the mouse whenever the animation tree doesn't have the condition set, that it is moving but I want to somehow find a way to transition (probably using something like blend or seek position) and calculate the correct angle for the bone so it not only transitions but also actually points to the correct angle without any strange offsets.
Thankyou