Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Alex Pires |
Hi guys!
I trying to make a 3D train over rails, so it will begin slow, then gain velocity when the user press right key, when the player release the key, the train slow down then stop.
I don’t know how to make use of lerp in this case (using PathFollow and offset value).
Any suggestions? Maybe an alternative way of doing this.
Thank you in advance!
Path
—|_PathFollow
-------------|_KinematicBody
obs.: I’m increasing the offset value of PathFollow, but I’d preffer use move_and_slide and avoid making use of offset (loss of gravity and etc), but if this works with offset it’s okay. When I use move_and_slide acceleration/deacceleration and gravity is okay, but how does the train follow the path (x+z axis) and turn along the rail?
P.S.: Sorry about my english
—UPDATE—
I got this to work, but I’m not happy with the results.
Issues:
- The train(hero) isn’t starting in the first point of the path.
- The train is not standing still.It’s moving backwards when stopped.
- The camera is also a crap when child of train or Path Follow. Seems to be unstable, trembling.
- Plus, the path created in Godot doesn’t seem to works well, had to create a new one in Blender then import.
Download my project [Godot 3.1]: https://yadi.sk/d/egenpGXWtAEA8Q (Yandex disk cloud)
Here is the code:
extends Spatial
var velocity = 0
var tempo =0
var acceleration = 0
onready var hero = $Path/PathFollow/hero
onready var pathf = $Path/PathFollow
func _process(delta):
tempo+=1*delta
velocity += (acceleration/tempo)*delta
pathf.offset += velocity*delta
# Stop it!
if velocity <= 0:
velocity=0
acceleration=0
# Set max velocity
elif velocity >=8:
velocity=8
if Input.is_action_pressed("ui_right"):
acceleration+=0.5
else: #release
acceleration-=16