Rotate RigidBody3D with mouse?

Godot Version

godot 4.2

Question

When I run the code, the rigid body rotates for a very short moment, then gets locked in a rotation. Looking up and down works fine, but not left to right.

If I understand correctly, the code runs every time there is an input, and if the input is mouse motion, it sets the rotation to that degree, but why does the y-axis rotation get locked?

When I print out “-event.relative.x * MOUSE_SENS” it’s updating.
but in the game, it stays locked to the rotation from the first time the code runs.

image

func _input(event):
  if event is InputEventMouseMotion:
	head.rotate_x(deg_to_rad(-event.relative.y * MOUSE_SENS))
	head.rotation.x = clamp(head.rotation.x,deg_to_rad(-89),deg_to_rad(89))
	rotate(Vector3(0, 1, 0), deg_to_rad(-event.relative.x * MOUSE_SENS))

add “head.” to “rotate(Vector3(0, 1, 0), deg_to_rad(-event.relative.x * MOUSE_SENS))” in the beggning to rotate that part

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