mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-05 10:09:47 +03:00
Now there's a base state_machine script, the StateMachine is separate from the physics body. I reworked the code to follow the GDscript guidelines in the official manual.
26 lines
770 B
GDScript
26 lines
770 B
GDScript
"""
|
|
The Player is a KinematicBody2D, in other words a physics-driven object.
|
|
It can move, collide with the world...
|
|
It HAS a state machine, but the body and the state machine are separate.
|
|
"""
|
|
extends KinematicBody2D
|
|
|
|
signal direction_changed(new_direction)
|
|
|
|
var look_direction = Vector2(1, 0) setget set_look_direction
|
|
|
|
func take_damage(attacker, amount, effect=null):
|
|
if self.is_a_parent_of(attacker):
|
|
return
|
|
$States/Stagger.knockback_direction = (attacker.global_position - global_position).normalized()
|
|
$Health.take_damage(amount, effect)
|
|
|
|
func set_dead(value):
|
|
set_process_input(not value)
|
|
set_physics_process(not value)
|
|
$CollisionPolygon2D.disabled = value
|
|
|
|
func set_look_direction(value):
|
|
look_direction = value
|
|
emit_signal("direction_changed", value)
|