Files
fps_project_1/scripts/recoil.gd

27 lines
901 B
GDScript

extends Node3D
var snap_amount : float = 10
var speed : float = 10
var current_rotation : Vector3
var target_rotation : Vector3
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
target_rotation = lerp(target_rotation, Vector3.ZERO, speed * delta)
current_rotation = lerp(current_rotation, target_rotation, snap_amount * delta)
basis = Quaternion.from_euler(current_rotation)
func add_recoil(recoil_amount,snap_change,speed_change) -> void:
snap_amount = snap_change
speed = speed_change
var recoil_x = recoil_amount.x
var recoil_y = randf_range(-recoil_amount.y,recoil_amount.y)
var recoil_z = randf_range(-recoil_amount.z,recoil_amount.z)
target_rotation += Vector3(recoil_x, recoil_y, recoil_z)