clamp not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pit

am I missing something? the clamp section seems to be doing nothing

func _input(event): 


if event is InputEventMouseMotion and GVC.menu_mode == false:
	rotate_y(deg2rad(-1 * event.relative.x) * MOUSE_SENSITIVITY)
	look_pivot.rotate_x(deg2rad(event.relative.y) * MOUSE_SENSITIVITY)
	look_pivot.rotation.x = clamp(look_pivot.rotation.x, deg2rad(-90), deg2rad(90))
elif event is InputEventMouseMotion and GVC.menu_mode == true:
	return

Log the values in the console then and see what the values are and how they are changing.

print(look_pivot.rotation.x, " ", clamp(look_pivot.rotation.x, deg2rad(-90), deg2rad(90)))

Juxxec | 2022-12-02 10:27

this is super weird. $LookPivot (is the node where I have my camera attached to) was rotated in the Y axis by 180°. for some reason, after setting it back to 0 and changing the inputs accordingly, the clamp section of the code started working again. Any ideas what the problem was?

pit | 2022-12-02 15:34

:bust_in_silhouette: Reply From: LordBoots

Make sure when you put anything into a scene that it’s set to the right -y direction. Now that you’ve fixed this take note of what direction the camera is pointing and that is the orientation any object should be imported and set to in scene.

This is a pretty common problem, I fought with this no more than 5 days ago when trying to figure out why my character wouldn’t turn the right direction.

The functions you’re using to rotate the objects uses a default global rotation, not the one you set.