+1 vote

I am making an 3D fps game, I have a player when it shoots the recoil moves the camera up, but it seems unnatural, I want it to be smooth and less rigid,I thought of trying to use lerp but im not sure on how to do this with camera movement I also thought of using linear interpolate but thats beyond me, as I dont exactly know what it does or how to use it!

Line of code where recoil happens:

if Input.isactionpressed("fire") and currentammo != 0 and currenthealth != 0 and canfire == true:
#Recoil
vertical.rotation
degrees.x += recoil

Also, Please suggest ways on improving this recoil, at the moment it only goes up so if you guys could suggest a way to make it similar to call of duty, or just improve it in general, I would appreciate it, thanks!

in Engine by (164 points)

maybe instead of doing it through code, you could make an animation and trigger it. It all depends on the person though, for some this will be harder, some, easier.

Thanks for the option but unfortunately I would like to control the recoil with numbers having an animation would limit me, thanks for commenting anyways.

Try this and see if it works.

if Input.is_action_pressed("fire") etc.
    vertical.rotation_degrees.x = lerp(vertical.rotation_degrees, vertical.rotation_degrees + recoil, .1)

not exactly sure if it will work.

Tried this, it produces the same results not smooth and jumpy

what is the difference between vertical.rotation_degrees.x and rotation_degrees.x ?

Oof might of made a mistake there I gotta check if I fixed it, it's supposed to be the Same vertical is an extra 3D node so I can turn the players head up without rotating the body

it is the same, I just thought vertical must be something I didn't know about. :)

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.