Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closest Point on Spline (+Offset) to some World Position
#3
(01-23-2018, 01:03 PM)_Aka_ Wrote: Hi,
This should answer your question:
Code:
Vector3 P;
float carTf = yourSpline.GetNearestPointTF(carTransform.position, out P);
Quaternion splineOrientation = yourSpline.GetOrientationFast(carTf);
//the projection is to handle possible scenarios where the car is not on the road
Vector3 carProjectionToRoadCenter = Vector3.ProjectOnPlane((carTransform.position - P), splineOrientation * Vector3.up);
float lanePosition = Vector3.Dot(carProjectionToRoadCenter, splineOrientation * Vector3.right);



Awesome, thank you! Makes sense to me. Can GetNearestPointTF be called safely during FixedUpdate? With Upwards of 20 cars calling it?
Reply


Messages In This Thread
RE: Closest Point on Spline (+Offset) to some World Position - by nomadigi - 01-23-2018, 04:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Generator gameobjects missing offset and rotated beewhale 5 419 08-30-2026, 07:51 PM
Last Post: beewhale
  Spline Issue Leading to Unity Freeze Pankaj09 1 201 08-24-2026, 11:28 PM
Last Post: _Aka_
  Connecting Multiple Spline Nodes Issue Ritesh Kadam 1 161 08-22-2026, 11:24 PM
Last Post: _Aka_
  Spline Spots from 2 samples. BitBlit 8 1,080 06-30-2026, 11:49 AM
Last Post: _Aka_

Forum Jump: