0 votes

I coded the recoil of the camera to rotate on the x axis but I'm running into an issue. After shooting for a short time the rotation of the clamp changes and I cannot look fully down and too far behind the player. I believe the recoil camera rotation is messing it up. Do you guys have any possible solution for something like this? Thanks in advance

https://youtu.be/WdzifU4b8-A

func _input(event):

if event is InputEventMouseMotion:

rotate\_y(deg2rad(-event.relative.x \* mouse\_sens))

head.rotate\_x(deg2rad(-event.relative.y \* mouse\_sens))

head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89))

func fire():

if Input.is_action_pressed("fire"):

var recoil = camera.rotate\_object\_local(Vector3(1,0,0),0.005)

recoil = get\_global\_transform().basis.x
in Engine by (12 points)

For future reference, this question was cross-posted on Reddit: https://www.reddit.com/r/godot/comments/kld3t9/clamping_question/

1 Answer

0 votes

(Cross-posting my answer from Reddit for posterity.)

It sounds like you're a victim of gimbal lock. To solve this in a durable way, you will have to think in 3D transforms instead of using angles. Using 3D transforms is more difficult at first, but the price is well worth it as soon as you need to rotate on more than one axis.

See Using 3D transforms in the documentation for more information.

by (10,950 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.