41 lines
1.1 KiB
GDScript
41 lines
1.1 KiB
GDScript
extends StateAnimatedActor
|
|
|
|
export (NodePath) var idle_node
|
|
export (NodePath) var move_node
|
|
|
|
onready var idle_state: State = get_node(idle_node)
|
|
onready var move_state: State = get_node(move_node)
|
|
|
|
func enter() -> void:
|
|
.enter()
|
|
animations.frame = 6
|
|
|
|
|
|
func process_input(_event: InputEvent) -> State:
|
|
move_component.get_movement_direction()
|
|
return null
|
|
|
|
func process_physics(delta: float) -> State:
|
|
parent.velocity.y += gravity * delta
|
|
|
|
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
|
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
|
|
# if parent.velocity.x != 0.0:
|
|
# parent.direction.x = parent.velocity.x
|
|
|
|
if move_component.get_movement_direction() != 0.0:
|
|
parent.transform.x.x = move_component.get_movement_direction()
|
|
# if move_component.flipped_sprite == false:
|
|
# #parent.scale.x = parent.direction.x * -1
|
|
# parent.transform.x.x = parent.direction.x * -1 # -1
|
|
# else:
|
|
# #parent.scale.x = parent.direction.x
|
|
# parent.transform.x.x = parent.direction.x # 1
|
|
|
|
if parent.is_on_floor():
|
|
if parent.velocity.x == 0:
|
|
return move_state
|
|
return idle_state
|
|
return null
|