Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple splines movement
#1
Smile 
Hello! I have a hard time figuring out how to do a basic spline movement system as I had using Unity Splines. Maybe you can help?

For context, I'm working on a drone flying game on mobile. The drone is controlled via a joystick UI that manage both acceleration/deceleration and offset around the spline. Everything work as expected, but the drone takes forever to turn a curve (using bezier). I have watched your API video and I though I understood the TF vs Distance differences, I guess I'm confused as to how to use that information.   Blush

The whole movement loop is done in an Update method:
Code:
        private void Update()
        {
            ReadJoystickDirection();
            EvaluateSpeed();
            MoveAlongSpline();
        }

The EvaluateSpeed part is straigthforward. We lerp to max speed on input.Started and lerp back to 0 if input.Canceled.

Here is the MoveAlongSpline method:
Code:
private void MoveAlongSpline()
{
    if (!IsMoving && _hasFinishedMoving)
        return;

    _splinePosition += CurrentSpeed * Time.deltaTime;

    // calculate position and rotation on the spline
    Vector3 splinePoint = _splineController.Spline.Interpolate(_splinePosition, Space.World);
    Vector3 tangent = _splineController.Spline.GetTangent(_splinePosition, Space.World);

    // calculate offset
    OffsetPosition();

    // Rotate the player to face the tangent and move the player along the spline
    _player.SetPositionAndRotation(splinePoint + _offset, Quaternion.LookRotation(tangent));

    // Update mini map icon position
    SplinePointUpdated?.Invoke(splinePoint);
}

I have tried to convert _splinePosition with float distance = _splineController.Spline.TFToDistance(_splineposition), but the behaviour was the same.

Any idea? Thanks Smile
Reply
#2
Hi,

Have you thought about using the Spline Controller instead of recreating its behavior via code? You can control the spline controller via APi. You will only have to set the offset and speed parameters, and the controller will take care of the rest.

If coding everything yourself is indeed what you want, then, and assuming CurrentSpeed is in distance/time:

Code:
    Vector3 splinePoint = _splineController.Spline.InterpolateByDistance(_splinePosition, Space.World);

This change should do it. If you still have issues, please let me know.
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply
#3
(02-20-2025, 06:07 PM)_Aka_ Wrote: Hi,

Have you thought about using the Spline Controller instead of recreating its behavior via code? You can control the spline controller via APi. You will only have to set the offset and speed parameters, and the controller will take care of the rest.

If coding everything yourself is indeed what you want, then, and assuming CurrentSpeed is in distance/time:

Code:
    Vector3 splinePoint = _splineController.Spline.InterpolateByDistance(_splinePosition, Space.World);

This change should do it. If you still have issues, please let me know.

You are totally right! I had the code done before implementing Curvy Splines 8, so I simply translated to it. I have redone the system to use SplineController instead and it works great.  Smile
Reply
#4
Glad to read that.
Have a nice day.
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Spawn at start/ end of splines rickgplus 4 232 03-21-2025, 12:34 PM
Last Post: _Aka_
  Any performance 'hacks' for scene with lots of splines rickgplus 1 118 03-18-2025, 10:11 PM
Last Post: _Aka_
  Mesh Generation between two splines vatan 4 438 02-14-2025, 07:11 AM
Last Post: vatan
Information New free asset: Converter For Dreamteck Splines _Aka_ 0 104 07-19-2024, 08:27 PM
Last Post: _Aka_

Forum Jump: