Rotation of 2 nodes causing problems

Godot Version

Godot 4


I’m trying to use the following tutorial to make a 3d camera controller, but when the characterbody3d and the springarm are created, they are at different rotations than eachother and to rotate either to try and line them up in the correct rotation, it completely breaks everything and the cam controls don’t behave correctly. I’d rather not change anything in the code, so if there is anyway to have them be created in the correct direction or anything else that will fix the issue please help.

I’ve cloned that repo and gave it a shot. noticed that when I try to move the mouse to move the camera, it rotates in the wrong axis (if I move the camera to the right, I would expect it to rotate along the xz plane, instead it rotates along the xy plane). is this the behavior you are running into?

If that is not the behavior you are running into could you please clarify the issue you are running into?

The project was originally written in 4.1, I don’t think there are any breaking changes between 4.1 and 4.2 so I don’t think the issue was caused there.

Whatever the issue is, I suspect it’s going to require changes to the code regarding calculating the new camera position based off of the user’s input.

I replaced the rotation function to do this instead

func _input(event):
	if event is InputEventMouseMotion:
		pivot.rotate_y(deg_to_rad(-event.relative.x * sens))
		pivot.rotate_x(deg_to_rad(-event.relative.y * sens))
		pivot.rotation.x = clamp(pivot.rotation.x, deg_to_rad(-90), deg_to_rad(45))

And it appears to behave reasonably for me. I’m not sure why this is needed, as according to the 3d editor we do want rotation along xz when moving the mouse laterally and the zy axis if moving the mouse vertically (I think, never touched 3d godot stuff before this), so the code provided by the repository should work better then what I’ve done.

I thought maybe the issue was that the rotation was relative to the body model so it’s axis are not placed the same as with the origin, however looking at the 3D view the gimbal appears to be consistent with the absolute orientation (for lack of a better word)

Your solution did not work, but I did realize that because the camOrigin was rotated 90 degrees, I had to change pivot.rotate_x to pivot.rotate_z instead and that fixed the issue of it rotating along the wrong axis.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.