EntityGib.gd 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. extends Node2D
  2. @export_enum("Spin", "Drop", "Poof") var gib_type := 0
  3. var visuals: Node = null
  4. var velocity := Vector2(0, 0)
  5. var direction := 1
  6. var entity_rotation := 0.0
  7. func _ready() -> void:
  8. if visuals == null:
  9. queue_free()
  10. return
  11. visuals.physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF
  12. add_child(visuals)
  13. visuals.process_mode = Node.PROCESS_MODE_DISABLED
  14. visuals.position = Vector2.ZERO
  15. match gib_type:
  16. 0:
  17. velocity = Vector2(100 * direction, -200)
  18. func _physics_process(delta: float) -> void:
  19. match gib_type:
  20. 0:
  21. spin_move(delta)
  22. 1:
  23. velocity.y += (15 / delta) * delta
  24. velocity.y = clamp(velocity.y, -INF, Global.entity_max_fall_speed)
  25. scale.y = -1
  26. global_position += velocity * delta
  27. func spin_move(delta: float) -> void:
  28. velocity.y += (15 / delta) * delta
  29. velocity.y = clamp(velocity.y, -INF, Global.entity_max_fall_speed)
  30. entity_rotation = (180 * direction)
  31. visuals.global_rotation_degrees = snapped(entity_rotation, 45)
  32. velocity.x = lerpf(velocity.x, 0, delta / 2)