When I try to manually compensate for the recoil, it rebounds it too far down.
I understand why this is happening but can find a fix.
Code and Screenshot Below:
extends Node3D
#Rotations
var current_rotation : Vector3
var target_rotation : Vector3
#Recoil vectors
var recoil : Vector3
var aim_recoil : Vector3
#Settings
var snap : float
var return_speed : float
func _process(delta):
# Lerp target rotation to (0,0,0) and lerp current rotation to target rotation
target_rotation = lerp(target_rotation, Vector3.ZERO, return_speed * delta)
current_rotation = lerp(current_rotation, target_rotation, snap * delta)
# Set rotation
rotation = current_rotation
# Camera z axis tilt fix, ignored if tilt intentional
# I have no idea why it tilts if recoil.z is set to 0
if recoil.z == 0 and aim_recoil.z == 0:
global_rotation.z = 0
func fire_recoil(is_aiming : bool = false):
if is_aiming:
target_rotation += Vector3(aim_recoil.x, randf_range(-aim_recoil.y, aim_recoil.y), randf_range(-aim_recoil.z, aim_recoil.z))
else:
target_rotation += Vector3(recoil.x, randf_range(-recoil.y, recoil.y), randf_range(-recoil.z, recoil.z))
func set_recoil(new_recoil : Vector3):
recoil = new_recoil
func set_aim_recoil(new_recoil : Vector3):
aim_recoil = new_recoil
func set_recoil_settings(new_snap:float, new_return_speed:float):
snap = new_snap
return_speed = new_return_speed