3D - I have a fire button that makes the camera move up(recoil), but it isnt smooth, how would I smooth it?

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

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.is_action_pressed(“fire”) and current_ammo != 0 and current_health != 0 and can_fire == 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!

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.

Millard | 2020-11-09 19:48

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.

Dragon20C | 2020-11-09 20:03

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.

Millard | 2020-11-10 00:19

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

Dragon20C | 2020-11-10 07:39

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

Millard | 2020-11-10 21:22

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

Dragon20C | 2020-11-10 21:37

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

Millard | 2020-11-11 00:41