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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Dummy spline points hnngaf 0 12 11-14-2019, 02:08 PM
Last Post: hnngaf
  Refresh spline doesn't seem to be working dazz777 4 56 11-13-2019, 11:13 PM
Last Post: _Aka_
  Same Spline Extrusion with variable width MarioBag 5 656 11-04-2019, 01:56 PM
Last Post: _Aka_
  Change curvy gizmos to show direction of spline Horibe 1 45 11-01-2019, 07:02 PM
Last Post: _Aka_

Forum Jump: