Gun recoil curve

This commit is contained in:
Rendo 2025-11-26 19:00:45 +05:00
commit 26a365478a
2 changed files with 24 additions and 3 deletions

View file

@ -1,16 +1,22 @@
extends WeaponState
@export var vertical_curve: Curve
@export var horizontal_curve: Curve
@export var raycast: RayCast3D
@export var emptyable: bool
@export var damage: int
@export var fire_timer: Timer
var bullets_shot: int = 0
func enter() -> void:
fire()
machine.animation_player.animation_finished.connect(on_animation_finished)
func exit() -> void:
bullets_shot = 0
machine.animation_player.animation_finished.disconnect(on_animation_finished)
func on_animation_finished(animation):
@ -26,6 +32,7 @@ func fire() -> void:
if machine.ammo == 0 or fire_timer.time_left > 0:
return
machine.ammo -= 1
bullets_shot += 1
machine.animation_player.stop()
machine.animation_player.play(with_morphems("shoot"))
@ -34,7 +41,7 @@ func fire() -> void:
raycast.get_collider().hp -= damage
fire_timer.start()
machine.player_camera.recoil(0,0.1)
machine.player_camera.recoil(horizontal_curve.sample(bullets_shot),vertical_curve.sample(bullets_shot))
func with_morphems(animation):
return machine.animation_prefix + ((animation+"_empty") if emptyable and machine.ammo == 0 else animation)