How to make the "sway" effect on weapons of FPS games

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

I actually managed to make it sway left and right but I can’t figure out how to do it vertically. Can someone please help me and explain what I have to add to the code?

extends Spatial

var mouse_move
var sway_threshold = 5
var sway_lerp = 5

export var sway_left : Vector3
export var sway_right : Vector3
export var sway_normal : Vector3

func _ready():
pass

func _input(event):
if event is InputEventMouseMotion:
mouse_move = -event.relative.x

func _process(delta):
if mouse_move != null:
if mouse_move > sway_threshold:
rotation = rotation.linear_interpolate(sway_left, sway_lerp * delta)
elif mouse_move < -sway_threshold:
rotation = rotation.linear_interpolate(sway_right, sway_lerp * delta)
else:
rotation = rotation.linear_interpolate(sway_normal, sway_lerp * delta)

:bust_in_silhouette: Reply From: Gil-Koren

Hopefully this video explains what you are looking for (not mine).

This is gonna sound funny but actually I had no idea how to do the sway effect so I just watched Garbaj’s second video on this topic, but it didn’t explain how to do it vertically and I don’t know how, so I’m just wondering what I can add to this.

Nuked Snake | 2021-12-26 22:34