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.
|
- extends Line2D
-
-
- export var max_length : int = 100 setget _set_max_length
- export var distance_between_points : float = 10
- export var decay_time : float = 0.1 setget _set_decay_time
-
- var last_point = null
- onready var parent = get_parent()
- onready var timer = $Timer
-
- func _set_max_length(l : int) -> void:
- if l > 0:
- max_length = l
-
- func _set_decay_time(d : float) -> void:
- if d >= 0:
- decay_time = 0
-
-
- func _ready():
- set_as_toplevel(true)
- show_behind_parent = true
- _reset_timer()
-
- func _process(delta):
- rotation = parent.rotation
- if points.size() < max_length:
- var point = _get_point()
- if point != null:
- add_point(point)
- if points.size() >= max_length:
- remove_point(0)
-
- func _get_point():
- var point = parent.global_position
- if last_point != null and point.distance_to(last_point) < distance_between_points:
- return null
- last_point = point
- return point
-
- func _reset_timer():
- if decay_time > 0:
- timer.stop()
- timer.start(decay_time)
-
-
- func _on_decay_timeout():
- if points.size() > 0:
- remove_point(0)
- _reset_timer()
|