Arcade racing demo got Godot 3.3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.0KB

  1. extends Line2D
  2. export var max_length : int = 100 setget _set_max_length
  3. export var distance_between_points : float = 10
  4. export var decay_time : float = 0.1 setget _set_decay_time
  5. var last_point = null
  6. onready var parent = get_parent()
  7. onready var timer = $Timer
  8. func _set_max_length(l : int) -> void:
  9. if l > 0:
  10. max_length = l
  11. func _set_decay_time(d : float) -> void:
  12. if d >= 0:
  13. decay_time = 0
  14. func _ready():
  15. set_as_toplevel(true)
  16. show_behind_parent = true
  17. _reset_timer()
  18. func _process(delta):
  19. rotation = parent.rotation
  20. if points.size() < max_length:
  21. var point = _get_point()
  22. if point != null:
  23. add_point(point)
  24. if points.size() >= max_length:
  25. remove_point(0)
  26. func _get_point():
  27. var point = parent.global_position
  28. if last_point != null and point.distance_to(last_point) < distance_between_points:
  29. return null
  30. last_point = point
  31. return point
  32. func _reset_timer():
  33. if decay_time > 0:
  34. timer.stop()
  35. timer.start(decay_time)
  36. func _on_decay_timeout():
  37. if points.size() > 0:
  38. remove_point(0)
  39. _reset_timer()