improved recoil, fixing bounce
This commit is contained in:
@@ -94,7 +94,8 @@ func shoot(delta):
|
||||
hitscan_fire()
|
||||
spawn_casing()
|
||||
|
||||
player.recoil.add_recoil(recoil_amount,10,10)
|
||||
player.recoil.add_recoil(Vector3(0,recoil_amount.y,recoil_amount.z),10,10)
|
||||
player.recoil.add_gun_recoil(recoil_amount.x)
|
||||
if fire_mode != 0:
|
||||
cycle_count -= 1
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -157,7 +157,8 @@ func fire(delta):
|
||||
instance_bullet.player_velocity = (player.velocity * player.transform.basis)
|
||||
instance_bullet.instance_bullethole = bullethole.instantiate()
|
||||
get_tree().get_root().add_child(instance_bullet)
|
||||
player.recoil.add_recoil(recoil_amount,10,recoil_speed_change)
|
||||
player.recoil.add_recoil(Vector3(0,recoil_amount.y,recoil_amount.z),10,recoil_speed_change)
|
||||
player.recoil.add_gun_recoil(recoil_amount.x)
|
||||
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(60))
|
||||
|
||||
func reload(delta):
|
||||
|
||||
Reference in New Issue
Block a user