Adds player attacking and blocking states

master
Joey Pollack 3 years ago
parent 1660300a0f
commit a1246c7557

@ -151,6 +151,10 @@ func do_movement(delta):
if accel_vec.length() > 0:
velocity += accel_vec.normalized() * Acceleration * delta
do_friction(delta)
func do_friction(delta):
var final_friction = Friction
if Input.is_action_pressed("Sprint"):
final_friction = Friction / SprintModifier

@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3 uid="uid://dxdomdgegktpc"]
[gd_scene load_steps=19 format=3 uid="uid://dxdomdgegktpc"]
[ext_resource type="Script" path="res://scenes/player/player.gd" id="1_dph0q"]
[ext_resource type="PackedScene" uid="uid://n4s4px2xqq2u" path="res://scenes/player/weapon.tscn" id="2_8s3rd"]
@ -7,6 +7,8 @@
[ext_resource type="Script" path="res://scenes/player/states/player_idle.gd" id="5_odcgr"]
[ext_resource type="Script" path="res://scenes/player/states/player_moving.gd" id="6_qawb5"]
[ext_resource type="Script" path="res://scenes/player/states/player_in_air.gd" id="7_akv1d"]
[ext_resource type="Script" path="res://scenes/player/states/player_attack.gd" id="8_m6spe"]
[ext_resource type="Script" path="res://scenes/player/states/player_blocking.gd" id="9_msxvu"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_ahdjc"]
radius = 0.275
@ -230,7 +232,20 @@ script = ExtResource("7_akv1d")
Self = NodePath("../..")
state_machine = NodePath("..")
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
[node name="PlayerAttack" type="Node" parent="StateMachine" node_paths=PackedStringArray("AnimPlayer", "Self", "state_machine")]
script = ExtResource("8_m6spe")
AnimPlayer = NodePath("../../AnimationPlayer")
Self = NodePath("../..")
state_machine = NodePath("..")
[node name="PlayerBlocking" type="Node" parent="StateMachine" node_paths=PackedStringArray("AnimPlayer", "Self", "state_machine")]
script = ExtResource("9_msxvu")
AnimPlayer = NodePath("../../AnimationPlayer")
Self = NodePath("../..")
state_machine = NodePath("..")
[connection signal="animation_finished" from="AnimationPlayer" to="StateMachine/PlayerAttack" method="_on_animation_player_animation_finished"]
[connection signal="animation_finished" from="AnimationPlayer" to="StateMachine/PlayerBlocking" method="_on_animation_player_animation_finished"]
[connection signal="area_entered" from="HurtBox" to="HurtBox" method="_on_area_entered"]
[connection signal="state_change" from="StateMachine" to="." method="_on_state_machine_state_change"]

@ -1,6 +1,7 @@
class_name PlayerAttack
extends State
@export var AnimPlayer: AnimationPlayer
@export var Self: CharacterBody3D
@ -12,9 +13,11 @@ func enter(params: Dictionary):
Acceleration = Self.get_acceleration()
Friction = Self.get_friction()
SprintModifier = Self.get_sprint_modifier()
AnimPlayer.play("Swing")
func exit():
pass
if AnimPlayer.is_playing():
AnimPlayer.stop()
func on_input(event: InputEvent):
pass
@ -22,6 +25,10 @@ func on_input(event: InputEvent):
func on_process(delta):
pass
func _on_animation_player_animation_finished(anim_name):
if anim_name == "Swing":
state_machine.transition("PlayerIdle", {})
func on_physics_process(delta):
if not Self.is_on_floor():
@ -29,15 +36,9 @@ func on_physics_process(delta):
return
Self.do_movement(delta)
if abs(Self.velocity.x) < 0.1 and abs(Self.velocity.z) < 0.1:
Self.velocity = Vector3.ZERO
state_machine.transition("PlayerIdle", {})
return
Self.do_friction(delta)
Self.face_mouse()
Self.move_and_slide()

@ -0,0 +1,41 @@
class_name PlayerBlocking
extends State
@export var AnimPlayer: AnimationPlayer
@export var Self: CharacterBody3D
func enter(params: Dictionary):
AnimPlayer.play("EnterBlock")
Self.velocity = Vector3(0, 0, 0)
func exit():
pass
func on_input(event: InputEvent):
pass
func on_process(delta):
pass
func on_physics_process(delta):
if Input.is_action_just_released("Block"):
AnimPlayer.play("ExitBlock")
if Input.is_action_just_pressed("Attack"):
state_machine.transition("PlayerAttack", {})
return
Self.do_friction(delta)
Self.face_mouse()
Self.move_and_slide()
func as_string():
return "PlayerAttack"
func _on_animation_player_animation_finished(anim_name):
if anim_name == "ExitBlock":
state_machine.transition("PlayerIdle", {})

@ -27,7 +27,7 @@ func on_physics_process(_delta):
state_machine.transition("PlayerMoving", {})
if Input.is_action_just_pressed("Attack"):
state_machine.transition("PlayerAttacking", {})
state_machine.transition("PlayerAttack", {})
if Input.is_action_pressed("Block"):
state_machine.transition("PlayerBlocking", {})

@ -28,6 +28,14 @@ func on_physics_process(delta):
state_machine.transition("PlayerInAir", {})
return
if Input.is_action_just_pressed("Attack"):
state_machine.transition("PlayerAttack", {})
return
if Input.is_action_pressed("Block"):
state_machine.transition("PlayerBlocking", {})
return
Self.do_movement(delta)

Loading…
Cancel
Save