0 votes

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 moveandslide and avoid making use of offset (loss of gravity and etc), but if this works with offset it's okay. When I use moveandslide 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
in Engine by (90 points)
reshown by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.