Skip to content

Commit bbaca23

Browse files
committed
Fix weapon offset, stagger assert fail
Reparented the weapons (sword and bullet) to the body, tweaked related code Fix #277 Prevented attack state from stacking on top of stagger Fix 279
1 parent 2c260e0 commit bbaca23

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

2d/finite_state_machine/player/Player.tscn

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
[ext_resource path="res://player/states/die.gd" type="Script" id=8]
1111
[ext_resource path="res://player/shadow.png" type="Texture" id=9]
1212
[ext_resource path="res://player/body.png" type="Texture" id=10]
13-
[ext_resource path="res://player/weapon/weapon_pivot.gd" type="Script" id=11]
14-
[ext_resource path="res://player/weapon/Sword.tscn" type="PackedScene" id=12]
15-
[ext_resource path="res://player/bullet/bullet_spawner.gd" type="Script" id=13]
13+
[ext_resource path="res://player/bullet/bullet_spawner.gd" type="Script" id=11]
14+
[ext_resource path="res://player/weapon/weapon_pivot.gd" type="Script" id=12]
15+
[ext_resource path="res://player/weapon/Sword.tscn" type="PackedScene" id=13]
1616
[ext_resource path="res://fonts/SourceCodePro-Bold.ttf" type="DynamicFontData" id=14]
1717
[ext_resource path="res://player/states/debug/state_name_displayer.gd" type="Script" id=15]
1818

@@ -126,45 +126,42 @@ _sections_unfolded = [ "Visibility" ]
126126

127127
[node name="BodyPivot" type="Position2D" parent="." index="3"]
128128

129-
editor/display_folded = true
130-
131129
[node name="Body" type="Sprite" parent="BodyPivot" index="0"]
132130

133131
position = Vector2( 0, -58.8242 )
134132
texture = ExtResource( 10 )
135133

136-
[node name="WeaponPivot" type="Position2D" parent="." index="4"]
134+
[node name="BulletSpawn" type="Node2D" parent="BodyPivot" index="1"]
137135

138136
editor/display_folded = true
139137
position = Vector2( 1.17401, -61.266 )
140138
script = ExtResource( 11 )
139+
_sections_unfolded = [ "Transform" ]
141140

142-
[node name="Offset" type="Position2D" parent="WeaponPivot" index="0"]
141+
[node name="CooldownTimer" type="Timer" parent="BodyPivot/BulletSpawn" index="0"]
143142

144-
position = Vector2( 110, 0 )
143+
process_mode = 1
144+
wait_time = 0.2
145+
one_shot = true
146+
autostart = false
145147

146-
[node name="Sword" parent="WeaponPivot/Offset" index="0" instance=ExtResource( 12 )]
148+
[node name="WeaponPivot" type="Position2D" parent="BodyPivot" index="2"]
147149

148-
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." index="5"]
150+
position = Vector2( 1.17401, -61.266 )
151+
script = ExtResource( 12 )
149152

150-
build_mode = 0
151-
polygon = PoolVector2Array( -20, 0, -20, -20, 20, -20, 20, 0 )
153+
[node name="Offset" type="Position2D" parent="BodyPivot/WeaponPivot" index="0"]
152154

153-
[node name="BulletSpawn" type="Node2D" parent="." index="6"]
155+
position = Vector2( 110, 0 )
154156

155-
editor/display_folded = true
156-
position = Vector2( 1.17401, -61.266 )
157-
script = ExtResource( 13 )
158-
_sections_unfolded = [ "Transform" ]
157+
[node name="Sword" parent="BodyPivot/WeaponPivot/Offset" index="0" instance=ExtResource( 13 )]
159158

160-
[node name="CooldownTimer" type="Timer" parent="BulletSpawn" index="0"]
159+
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." index="4"]
161160

162-
process_mode = 1
163-
wait_time = 0.2
164-
one_shot = true
165-
autostart = false
161+
build_mode = 0
162+
polygon = PoolVector2Array( -20, 0, -20, -20, 20, -20, 20, 0 )
166163

167-
[node name="StateNameDisplayer" type="Label" parent="." index="7"]
164+
[node name="StateNameDisplayer" type="Label" parent="." index="5"]
168165

169166
editor/display_folded = true
170167
anchor_left = 0.0
@@ -192,12 +189,12 @@ max_lines_visible = -1
192189
script = ExtResource( 15 )
193190
_sections_unfolded = [ "Rect", "custom_fonts" ]
194191

195-
[connection signal="state_changed" from="StateMachine" to="StateNameDisplayer" method="_on_StateMachine_state_changed"]
192+
[connection signal="state_changed" from="StateMachine" to="BodyPivot/WeaponPivot/Offset/Sword" method="_on_StateMachine_state_changed"]
196193

197-
[connection signal="state_changed" from="StateMachine" to="WeaponPivot/Offset/Sword" method="_on_StateMachine_state_changed"]
194+
[connection signal="state_changed" from="StateMachine" to="StateNameDisplayer" method="_on_StateMachine_state_changed"]
198195

199196
[connection signal="animation_finished" from="AnimationPlayer" to="StateMachine" method="_on_animation_finished"]
200197

201-
[connection signal="attack_finished" from="WeaponPivot/Offset/Sword" to="StateMachine/Attack" method="_on_Sword_attack_finished"]
198+
[connection signal="attack_finished" from="BodyPivot/WeaponPivot/Offset/Sword" to="StateMachine/Attack" method="_on_Sword_attack_finished"]
202199

203200

2d/finite_state_machine/player/player_state_machine.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func _input(event):
2727
otherwise we let the state node handle it
2828
"""
2929
if event.is_action_pressed("attack"):
30-
if current_state == $Attack:
30+
if current_state in [$Attack, $Stagger]:
3131
return
3232
_change_state("attack")
3333
return

2d/finite_state_machine/player/states/motion/motion.gd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,3 @@ func get_input_direction():
1414
func update_look_direction(direction):
1515
if direction and owner.look_direction != direction:
1616
owner.look_direction = direction
17-
if not direction.x in [-1, 1]:
18-
return
19-
owner.get_node("BodyPivot").set_scale(Vector2(direction.x, 1))

2d/finite_state_machine/player/weapon/weapon_pivot.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extends Position2D
33
var z_index_start = 0
44

55
func _ready():
6-
$"..".connect("direction_changed", self, '_on_Parent_direction_changed')
6+
owner.connect("direction_changed", self, '_on_Parent_direction_changed')
77
z_index_start = z_index
88

99
func _on_Parent_direction_changed(direction):

0 commit comments

Comments
 (0)