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


Messages In This Thread
Simple splines movement - by shills - 02-19-2025, 07:54 PM
RE: Simple splines movement - by _Aka_ - 02-20-2025, 06:07 PM
RE: Simple splines movement - by shills - 02-24-2025, 04:26 PM
RE: Simple splines movement - by _Aka_ - 02-26-2025, 09:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connections Between Opposing Splines lockiidraws 1 587 12-04-2025, 02:14 PM
Last Post: _Aka_
  Spawn at start/ end of splines rickgplus 4 2,883 03-21-2025, 12:34 PM
Last Post: _Aka_
  Any performance 'hacks' for scene with lots of splines rickgplus 1 1,820 03-18-2025, 10:11 PM
Last Post: _Aka_
  Mesh Generation between two splines vatan 4 3,638 02-14-2025, 07:11 AM
Last Post: vatan

Forum Jump: