Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Steer Towards Spline
#1
I have a manual user controlled vehicle that a user will drive down a road created with a Curvy volume extrusion. When the user is not moving the horizontal axis (Steering), I would like to auto-steer the vehicle to be parallel with the underlying spline. I have tried several things and would appreciate your input as to the best way. Firstly, I use GetNearestPointTF(vehiclePosition) and interpolate the world position and can place marker in the correct GOAL position. Where I am stuck is figuring out the rotation that an object following the path at GOAL position would have? An approach I tried is to attach a VolumeController to a DEBUG object and attempt to set its .Position property to the TF value from GetNearestPointTF(vehiclePosition) above. Then, I could use this object's rotation as the "ideal" rotation at this point. However, setting .Position to the same TF value used to place the GOAL object above lags way behind the object. The farther away from start I get, the more behind the position is. So, what am I doing wrong with the .Position setting and, is there a whole lot better and easier way to accomplish this?
Reply
#2
Hi,
The CurvySpline class has a GetTangent method that should be the forward direction that you are looking for. Is my answer correct, or did I misunderstood your need?
Have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
(08-30-2019, 06:33 PM)_Aka_ Wrote: Hi,
The CurvySpline class has a GetTangent method that should be the forward direction that you are looking for. Is my answer correct, or did I misunderstood your need?
Have a nice day

Thanks, that answers part of my question. A second part is why this does not work:

Code:
       // In the following line, player is a user-controlled object near a spline and without a curvy controller component.      
       float tf = spline.GetNearestPointTF(player.localPosition);        
       Vector3 nearestWorldPositionOnSpline = spline.transform.TransformPoint(spline.InterpolateFast(tf));        
       // In this following line, goal is a visual game object (red sphere) manually positioned on the spline (at tf) to mark where I want "controller" below to ALSO be positioned... It is in the correct/expected position.
       goal.position = new Vector3(nearestWorldPositionOnSpline.x, target.position.y, nearestWorldPositionOnSpline.z);
       // Finally, I attempt to set the location of a gameobject controlled by a Curvy VolumeController to the same exact location marked by the red sphere... 
       controller.Stop(); //assumed to be unnecessary, added for completeness 
       controller.Position = tf;
       controller.Speed = 0f;  //assumed to be unnecessary, added for completeness
       controller.Play();  //assumed to be unnecessary, added for completeness
       // The game object containing "controller" is not the same position as the red sphere. If the player starts at the beginning of the spline, they are close. As player moves away from the start of the spline, the controller and red sphere are increasingly farther apart.
Reply
#4
Hi,
spline.GetNearestPointTF takes a position in the local space of the spline. This means that
spline.GetNearestPointTF(player.localPosition)
is correct only if both spline and player have the same transform.
You should use instead
spline.GetNearestPointTF(spline.InverseTransformPoint(player.transform.position))
Does this fix your issue?
Have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Disable a spline's gizmo when not selected or disabled. mikechr2000 1 154 02-03-2025, 09:34 AM
Last Post: _Aka_
Information Questions regarding spline colliders and collisions with rigidbodies Spyboticer 7 551 01-20-2025, 12:25 PM
Last Post: _Aka_
  Extrude mesh along spline. New and confused user GhostStalker 3 240 01-02-2025, 09:58 AM
Last Post: _Aka_
  Newly created spline is invisible quickytools 7 554 12-21-2024, 10:14 AM
Last Post: _Aka_

Forum Jump: