improved recoil, fixing bounce
This commit is contained in:
@@ -404,6 +404,7 @@ _data = {
|
|||||||
[node name="mac10" node_paths=PackedStringArray("flare_light", "anim_player", "barrel_raycast", "casing_ejector", "mag_ejector", "audio_fire", "audio_empty", "audio_reload") instance=ExtResource("1_nb4p5")]
|
[node name="mac10" node_paths=PackedStringArray("flare_light", "anim_player", "barrel_raycast", "casing_ejector", "mag_ejector", "audio_fire", "audio_empty", "audio_reload") instance=ExtResource("1_nb4p5")]
|
||||||
script = ExtResource("2_tskiy")
|
script = ExtResource("2_tskiy")
|
||||||
gun_name = "Mac 10"
|
gun_name = "Mac 10"
|
||||||
|
recoil_amount = Vector3(0.05, 0.05, 0.05)
|
||||||
max_ammo = 20
|
max_ammo = 20
|
||||||
bullet_damage = 2
|
bullet_damage = 2
|
||||||
bullet_speed = 1500
|
bullet_speed = 1500
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ func shoot(delta):
|
|||||||
hitscan_fire()
|
hitscan_fire()
|
||||||
spawn_casing()
|
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:
|
if fire_mode != 0:
|
||||||
cycle_count -= 1
|
cycle_count -= 1
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ var speed : float = 10
|
|||||||
var current_rotation : Vector3
|
var current_rotation : Vector3
|
||||||
var target_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.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
@@ -16,6 +23,12 @@ func _process(delta: float) -> void:
|
|||||||
current_rotation = lerp(current_rotation, target_rotation, snap_amount * delta)
|
current_rotation = lerp(current_rotation, target_rotation, snap_amount * delta)
|
||||||
basis = Quaternion.from_euler(current_rotation)
|
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:
|
func add_recoil(recoil_amount,snap_change,speed_change) -> void:
|
||||||
#set to provided snap/speed changes
|
#set to provided snap/speed changes
|
||||||
snap_amount = snap_change
|
snap_amount = snap_change
|
||||||
@@ -28,3 +41,6 @@ func add_recoil(recoil_amount,snap_change,speed_change) -> void:
|
|||||||
|
|
||||||
#add to target rotation
|
#add to target rotation
|
||||||
target_rotation += Vector3(recoil_x, recoil_y, recoil_z)
|
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.player_velocity = (player.velocity * player.transform.basis)
|
||||||
instance_bullet.instance_bullethole = bullethole.instantiate()
|
instance_bullet.instance_bullethole = bullethole.instantiate()
|
||||||
get_tree().get_root().add_child(instance_bullet)
|
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))
|
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(60))
|
||||||
|
|
||||||
func reload(delta):
|
func reload(delta):
|
||||||
|
|||||||
Reference in New Issue
Block a user