Mathilde Grapin
7038d29d87
Add simple player movement with a finite state machine. Add enemy that can move to target point. Add ground through a tilemap and wall that player and enemy cannot cross.
25 lines
680 B
GDScript
25 lines
680 B
GDScript
class_name PlayerWalkState
|
||
extends PlayerState
|
||
|
||
func enter(_msg := {}):
|
||
player.animation_player.play("walk")
|
||
|
||
func physics_update(_delta):
|
||
var direction = get_input_direction()
|
||
player.velocity = direction * player.speed
|
||
|
||
player.move_and_slide() # this method calculate with delta, we don’t need to do it
|
||
|
||
if player.velocity == Vector2.ZERO:
|
||
state_machine.transition_to("Idle")
|
||
|
||
func get_input_direction():
|
||
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||
|
||
if Input.is_action_pressed("move_left"):
|
||
player.sprite.flip_h = true
|
||
elif Input.is_action_pressed("move_right"):
|
||
player.sprite.flip_h = false
|
||
|
||
return direction
|