#Fixing recoil fps

1 messages · Page 1 of 1 (latest)

uncut surge
#

Hay I am having a problem where after moving my mouse from when I was shooting it snaps back to where it was before shooting as when as it the recoil not applying when looking side to side if anyone needs more context let me know @ me (for an fps)

Player code
func _handle_mouse_movement(event: InputEventMouseMotion) -> void:
rotate_y(deg_to_rad(-event.relative.x * mouse_sensitivity))
pitch = clamp(pitch - event.relative.y * mouse_sensitivity, -90, 90)
camera.rotation_degrees.x = pitch

Gun code
func apply_recoil():
var tween = create_tween()
var recoil_amount = deg_to_rad(recoil_intensity)
tween.tween_property(camera, "rotation:x", camera.rotation.x + recoil_amount, 0.08).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
tween.tween_property(camera, "rotation:x", camera.rotation.x, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)

tawny zinc
#

nothing in there moves the mouse -- is the problem that you're seeing the camera move in a way you'd like to avoid? That makes sense, since you have a tween there and they'll tend to fight

#

I'd suggest you use a layer of indirection, a few nested Node3Ds so that each of them can be separately modified, something like:

(root)
 +-> Node3D PlayerHead (moved around in space + rotated with mouselook)
   +-> Node3D Shakycam (this is what your apply_recoil modifies in little steps -- bonus, if you want, it can jig it in xyz not just rotation)
     +-> Camera3D  (ok, this could _be_ shakycam if you wanted. But what if you want more layers of indirection later :-} )