19 lines
469 B
GDScript
19 lines
469 B
GDScript
class_name PlayerWalkState
|
|
extends PlayerState
|
|
|
|
func enter(_msg := {}):
|
|
player.animation_player.play("walk")
|
|
|
|
func physics_update(delta):
|
|
var direction = player.get_input_direction()
|
|
var velocity = direction * player.speed
|
|
|
|
player.flip_sprite()
|
|
|
|
var collision = player.move_and_collide(velocity * delta)
|
|
if collision and Input.is_action_pressed("hit"):
|
|
state_machine.transition_to("Hit")
|
|
|
|
if velocity == Vector2.ZERO:
|
|
state_machine.transition_to("Idle")
|