32 lines
775 B
GDScript
32 lines
775 B
GDScript
extends MeshInstance3D
|
|
|
|
signal speed_changed(new_speed: float)
|
|
|
|
@export_group("Train")
|
|
@export var base_speed: float = 15.0
|
|
@export var max_speed: float = 50.0
|
|
@export var min_speed: float = 3.0
|
|
@export var acceleration: float = 12.0
|
|
|
|
var current_speed: float = 15.0
|
|
|
|
func _ready() -> void:
|
|
current_speed = base_speed
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
_handle_input(delta)
|
|
|
|
|
|
func _handle_input(delta: float) -> void:
|
|
if Input.is_action_pressed("speed_up"):
|
|
current_speed = min(current_speed + acceleration * delta, max_speed)
|
|
speed_changed.emit(current_speed)
|
|
elif Input.is_action_pressed("speed_down"):
|
|
current_speed = max(current_speed - acceleration * delta, min_speed)
|
|
speed_changed.emit(current_speed)
|
|
|
|
|
|
func get_speed() -> float:
|
|
return current_speed
|