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
  Best practice for mass-object instancing along 100km spline (railways) plus streaming bs@vectorvision.de 6 90 09-13-2019, 12:30 PM
Last Post: _Aka_
  How to spawn GameObjects on corners of the liinear spline? Pixel Flipper 4 50 09-13-2019, 08:04 AM
Last Post: Pixel Flipper
  How to properly set UV for extruded spline texture Pixel Flipper 3 60 09-05-2019, 11:55 AM
Last Post: _Aka_
  Basis Spline Wanderfalke 2 72 08-30-2019, 12:35 PM
Last Post: Wanderfalke

Forum Jump: