Godot Version
4.6.2.stable
Question
This was a re-upload because I don’t think I knew what it was well enough before, so I tried doing a bit more bug fixing. I found that the z direction of the neck is reversed, or something like that. The clamp() that I am trying to use to allow you to look forward from -x to x is instead going in reverse, so I can look between those same max and min, but instead of facing forward I am facing backwards.
I tried looking for a way to just use the other side of the clamp() but it seems more complicated than I thought. Another detail is that the max and min of this clamp need to rotate, because this clamp is tied to a vehicle so you can only look forwards, and the vehicle needs to rotate.
func _unhandled_input(event: InputEvent) -> void:
#Capturing a mouse means it isn't visible and can't be seen
if event is InputEventMouseButton:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
elif event.is_action_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
Neck.rotation_degrees.y += (-event.relative.x * 0.5)
Head.rotation_degrees.x += (-event.relative.y * 0.5)
Neck.rotation_degrees.y = clamp(Neck.rotation_degrees.y, -80, 80)
Head.rotation_degrees.x = clamp(Head.rotation_degrees.x, -45, 45)
This code is what I used to make the camera follow the neck/head smoothly, the comment is what I will hopefully be able to replace the global position one, but I was trying to limit variables.
print("Head y rotation:",Head.rotation_degrees.y," Neck y rotation:",Neck.rotation_degrees.y," Vehicle y rotation:",rotation_degrees.y)
Camera.global_position = lerp(Camera.global_position,Head.global_position,follow_speed)
Camera.global_rotation = Vector3(Head.global_rotation.x,Neck.global_rotation.y,Head.global_rotation.z)
#Camera.global_rotation = Vector3(lerp_angle(Camera.global_rotation.x,Head.global_rotation.x,LOOK_SPEED),lerp_angle(Camera.global_rotation.y,Neck.global_rotation.y,LOOK_SPEED),lerp_angle(Camera.global_rotation.z,Head.global_rotation.z,LOOK_SPEED))