Question about Rotating Transforms

Godot Version

4.3

Question

Hey all, I am running into an issue when I try to tween from one transform to a rotated version of the same transform.

For some context, I’m trying to make it so when the player character hits a part of an enemy, the part that was hit rotates the bone thus rotating the connecting mesh.

All I am really doing is taking the pose of the bone and rotating it by 45 degree.

rest_pose = mesh.skin.get_bind_pose(bind_index); 
wiggle_pose = rest_pose.rotated(Vector3.UP, deg_to_rad(45));

Then I just tween from one pose to the other.

current_pose = rest_pose;
tween = create_tween();
tween.tween_property(self, "current_pose", wiggle_pose, 1).set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_IN); 

Lastly to animate it I set the bind pose to the current pose.

mesh.skin.set_bind_pose(bind_index, current_pose);

The problem is when I run the game, the mesh seems to offset itself despite just rotating it.
capture
So my questions is why does this happen and is there anything I can do to fix it? It is strange too because I have been able to get this to work on other parts of the model.
capture
My best guess is that it has something to do with the bone on the skeleton being at a 45 degree angle but otherwise I am pretty stumped. Thanks for any help, I really appreciate it!

My best guess is that you try to rotate the mesh in the world around the Y-axis instead of the Y-axis of the bone itself. So if it is not completely horizontal, then it would create an offset. I’m curious of the final solution.

Regards

Ludo

I think there could be a gimball lock effect at play here (2:57 shows how the gimball effect can affect the offset of the rotating object)

Potentially tweening the whole Transform3D can’t handle the gimball lock properly and produces this weird effect.
I would suggest maybe to try tweening only the rotation itself, ideally by the Quaternion.
This is my little demo code, you’ll have to adjust it to your project, or share your whole script here so that I can help you adjust it.

func _ready() -> void:
	var target_rotation = transform.basis.rotated(Vector3.UP, deg_to_rad(45)).get_rotation_quaternion()
	
	var tween = create_tween()
	tween.tween_property(self, "quaternion", target_rotation , 1)