player_controller.gd 796 B

123456789101112131415161718192021222324252627
  1. extends CharacterBody2D
  2. # The Player is a CharacterBody2D, in other words a physics-driven object.
  3. # It can move, collide with the world, etc...
  4. # The player has a state machine, but the body and the state machine are separate.
  5. signal direction_changed(new_direction)
  6. var look_direction = Vector2.RIGHT:
  7. set(value):
  8. look_direction = value
  9. set_look_direction(value)
  10. func take_damage(attacker, amount, effect = null):
  11. if is_ancestor_of(attacker):
  12. return
  13. $States/Stagger.knockback_direction = (attacker.global_position - global_position).normalized()
  14. $Health.take_damage(amount, effect)
  15. func set_dead(value):
  16. set_process_input(not value)
  17. set_physics_process(not value)
  18. $CollisionPolygon2D.disabled = value
  19. func set_look_direction(value):
  20. emit_signal("direction_changed", value)