Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
SantiMun's avatar
SantiMun
Honored Guest
13 years ago

Suggestions on track-based demo

Hey all!

Basically I'm working on a demo in Unity where the character model is on a chair and moves along an invisible rail and goes through a "tour" around the terrain. I am using splines to make the rail (bought Super Splines in the Asset Store) and everything so far is going as expected except for the fact that when I am adding more than two nodes on the spline, the speed in which the model on the spline moves is inconsistent.
I'm not sure why this is the case and was wondering if you all had any suggestions. Is there a way to edit the movement speed? I'd like for the movement on the rail to be consistent except at certain "points of interest" where then I would like the speed to be slowed down for a short period and then resume normal speed.
Right now though I would just like to solve the inconsistent speed issue.

Are splines not the answer for what I'm trying to achieve (on rails, consistent character movement)? Let me know if any screen shots will help get my point across and I'll upload them when I'm off work.

Thanks for reading!

7 Replies

Replies have been turned off for this discussion
  • drash's avatar
    drash
    Heroic Explorer
    I haven't used that particular asset (good to know about it though!), but you're going to need to look to see if it has a feature that lets you normalize the speed so that interpolating between two points in the spline will be linear. Hopefully it also has support for easing in and out as well which would let you smoothly start and stop at the end points.

    I've used CameraPath from the asset store for flight paths, and while it could be easier to use when it comes to making one spline begin where another ends, it does have normalization and easing options.
  • I recommend that you control the speed of the mover yourself and use the GetClosestPointParam() to stay on the spline. So for each frame you will do the following:

    - Move your character forward by velocity*deltaTime (you control the velocity, using acceleration)
    - Now move your character to the closest point on the spline

    Something like:

    public class MySplineMover : MonoBehaviour
    {
    public Spline spline;
    public float acceleration = 0.5f;
    public float maxSpeed = 2f;
    public float speed = 0f;

    void Update( )
    {
    speed = Mathf.min(speed + acceleration*Time.deltaTime, maxSpeed);
    Vector3 targetPosition = transform.position + transform.forward * speed * Time.deltaTime;

    float param = SplineUtils.WrapValue( spline.GetClosestPointParam( targetPosition, 10), 0f, 1f, WrapMode.Clamp);

    transform.position = spline.GetPositionOnSpline( param );
    transform.rotation = spline.GetOrientationOnSpline( param );
    }
    }
  • You might want to try just setting keyframes in unity directly-

    In the animation window there's a good deal of keyframe control. It's pretty straightforward adjusting the curve and tangent types between keyframes.

    Something that may make it easier is to script out on paper exactly what you want second to second.
  • Thank you all for the suggestions! I'll look into these over the week and let you know if any worked best for what I'm trying to do. Such a helpful community here :D
  • Ah! I am doing something very similar. Were you able to keep the view forward? I just purchased the same spline package and after the "track" turned, I was then riding backwards :lol: I need to keep the player looking in the same direction as the splines, any help would be greatly appreciated!
  • "ElementalSpark" wrote:
    Ah! I am doing something very similar. Were you able to keep the view forward? I just purchased the same spline package and after the "track" turned, I was then riding backwards :lol: I need to keep the player looking in the same direction as the splines, any help would be greatly appreciated!

    That is what the
    transform.rotation = spline.GetOrientationOnSpline( param );

    in my preview code sample would do. You also need to make sure the "Rotation Mode" of your spline is set to Tangent.

  • That is what the
    transform.rotation = spline.GetOrientationOnSpline( param );

    in my preview code sample would do. You also need to make sure the "Rotation Mode" of your spline is set to Tangent.


    Excellent, thank you! I found that I was selecting the wrong object to have it follow.. All is right in the world now, although I may mess with the code you gave above and see if I can refine my effect a bit. :)