I can't make a WASD-controlled object move stroked along a curve

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gryphonchik

Can you please tell me how to make the movement of the train on a curve. That the control was the player.

:bust_in_silhouette: Reply From: spaceyjase

There’s an example in the docs traversing a curve:

And while it’s not perhaps the answer you want, it’s the simplest example. A short example from a project is grenade projectile height following along a curve (C#):

translation = GlobalTranslation.MoveToward(endPosition, moveSpeed * delta);
translation.y = curve.Interpolate(distanceNormalized);
GlobalTranslation = translation;

And if your game is using a PathFollow node, you essentially really only need to change its offset value based on speed (which can be controlled via input):

func _process(delta: float) -> void:
    _speed = min(_speed + _acceleration * delta, SPEED_MAX)
    _path_follow.offset += _speed * delta

Again, an example from an on-rails shooter (the path is defined in game, player is a PathFollow node:

func _set_speed(speed: float, delta: float) -> void:
    offset += speed * delta