improved recoil, fixing bounce
This commit is contained in:
@@ -5,6 +5,13 @@ var speed : float = 10
|
||||
var current_rotation : Vector3
|
||||
var target_rotation : Vector3
|
||||
|
||||
var head_current_rotation : float
|
||||
var gun_recoil_target_rotation : float = 0
|
||||
var gun_recoil
|
||||
|
||||
@onready var head: Node3D = $".."
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
@@ -16,6 +23,12 @@ func _process(delta: float) -> void:
|
||||
current_rotation = lerp(current_rotation, target_rotation, snap_amount * delta)
|
||||
basis = Quaternion.from_euler(current_rotation)
|
||||
|
||||
#Handle Gun Recoil
|
||||
head_current_rotation = lerp(head_current_rotation, gun_recoil_target_rotation, delta * 10)
|
||||
gun_recoil = lerp(head_current_rotation,gun_recoil_target_rotation, delta * snap_amount)
|
||||
head.rotation.x = clamp(head.rotation.x + gun_recoil, deg_to_rad(-90), deg_to_rad(85))
|
||||
gun_recoil_target_rotation -= gun_recoil
|
||||
|
||||
func add_recoil(recoil_amount,snap_change,speed_change) -> void:
|
||||
#set to provided snap/speed changes
|
||||
snap_amount = snap_change
|
||||
@@ -28,3 +41,6 @@ func add_recoil(recoil_amount,snap_change,speed_change) -> void:
|
||||
|
||||
#add to target rotation
|
||||
target_rotation += Vector3(recoil_x, recoil_y, recoil_z)
|
||||
|
||||
func add_gun_recoil(recoil_amount):
|
||||
gun_recoil_target_rotation += recoil_amount
|
||||
|
||||
Reference in New Issue
Block a user