26 lines
872 B
GDScript
26 lines
872 B
GDScript
extends Node3D
|
|
|
|
var recoil_amount : Vector3 = Vector3(.1,0,0)
|
|
var snap_amount : float = 10
|
|
var speed : float = 4
|
|
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) -> void:
|
|
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)
|