01-23-2018, 04:54 PM
(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?