From 26a365478a39ae4745cea1a96d82f92a205d1ad8 Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 26 Nov 2025 19:00:45 +0500 Subject: [PATCH 1/2] Gun recoil curve --- scenes/weapons/starting_pistol.tscn | 18 ++++++++++++++++-- .../weapon_system/gun/semi_auto_shoot_state.gd | 9 ++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/scenes/weapons/starting_pistol.tscn b/scenes/weapons/starting_pistol.tscn index e0d6842..d03a171 100644 --- a/scenes/weapons/starting_pistol.tscn +++ b/scenes/weapons/starting_pistol.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=6 format=3 uid="uid://djwjl8xll53vn"] +[gd_scene load_steps=8 format=3 uid="uid://djwjl8xll53vn"] [ext_resource type="Script" uid="uid://e6lqknfl4ngt" path="res://scripts/weapon_system/weapon_substate_machine.gd" id="1_g7s1i"] [ext_resource type="Script" uid="uid://ofv4e3dsfe8" path="res://scripts/weapon_system/gun/idle_state.gd" id="2_cmn6f"] @@ -6,6 +6,18 @@ [ext_resource type="Script" uid="uid://hmekwp8444ao" path="res://scripts/weapon_system/gun/reload_state.gd" id="4_hoqxt"] [ext_resource type="Script" uid="uid://bmj0bwy2tlian" path="res://scripts/weapon_system/gun/intro_state.gd" id="5_ud1dr"] +[sub_resource type="Curve" id="Curve_cmn6f"] +_limits = [0.0, 0.1, 0.0, 20.0] +_data = [Vector2(0, 0.1), 0.0, -0.008247263, 0, 0, Vector2(20, 0), -2.2834061e-05, 0.0, 0, 0] +point_count = 2 +metadata/_snap_enabled = true +metadata/_snap_count = 8 + +[sub_resource type="Curve" id="Curve_016ti"] +_limits = [-0.02, 0.02, 0.0, 20.0] +_data = [Vector2(0, -9.313226e-10), 0.0, 0.0, 0, 0, Vector2(4.959569, 0.0044327714), 0.0, 0.0, 0, 0, Vector2(9.919138, -0.0075840354), 0.0, 0.0, 0, 0, Vector2(15.09434, 0.011533612), 0.0, 0.0, 0, 0, Vector2(20, -0.014684878), 0.0, 0.0, 0, 0] +point_count = 5 + [node name="StartingPistol" type="Node" node_paths=PackedStringArray("enter_state")] script = ExtResource("1_g7s1i") animation_prefix = &"baked_sp_" @@ -19,6 +31,8 @@ emptyable = true [node name="Shoot" type="Node" parent="." node_paths=PackedStringArray("fire_timer")] script = ExtResource("3_016ti") +vertical_curve = SubResource("Curve_cmn6f") +horizontal_curve = SubResource("Curve_016ti") emptyable = true damage = 22 fire_timer = NodePath("../FireTimer") @@ -32,5 +46,5 @@ script = ExtResource("5_ud1dr") emptyable = true [node name="FireTimer" type="Timer" parent="."] -wait_time = 0.2 +wait_time = 0.15 one_shot = true diff --git a/scripts/weapon_system/gun/semi_auto_shoot_state.gd b/scripts/weapon_system/gun/semi_auto_shoot_state.gd index d554c5f..06ae88a 100644 --- a/scripts/weapon_system/gun/semi_auto_shoot_state.gd +++ b/scripts/weapon_system/gun/semi_auto_shoot_state.gd @@ -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) From 5a3fc037482f3cf49e7b556f39ededadef36d9c3 Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 26 Nov 2025 19:02:01 +0500 Subject: [PATCH 2/2] gun recoil fix --- scenes/weapons/starting_pistol.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scenes/weapons/starting_pistol.tscn b/scenes/weapons/starting_pistol.tscn index d03a171..e3c1de9 100644 --- a/scenes/weapons/starting_pistol.tscn +++ b/scenes/weapons/starting_pistol.tscn @@ -8,7 +8,7 @@ [sub_resource type="Curve" id="Curve_cmn6f"] _limits = [0.0, 0.1, 0.0, 20.0] -_data = [Vector2(0, 0.1), 0.0, -0.008247263, 0, 0, Vector2(20, 0), -2.2834061e-05, 0.0, 0, 0] +_data = [Vector2(0, 0.1), 0.0, 0.0, 0, 0, Vector2(20, 0.1), -2.2834061e-05, 0.0, 0, 0] point_count = 2 metadata/_snap_enabled = true metadata/_snap_count = 8