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
  Best way to duplicate a spline with an offset Kapistijn 8 1,394 04-12-2026, 03:18 PM
Last Post: _Aka_
  Control Point Interpolation Overrides. rickgplus 1 541 12-11-2025, 08:52 AM
Last Post: _Aka_
Smile Constant speed along a spline? tfishell 1 662 11-13-2025, 11:32 AM
Last Post: _Aka_
  SplineController Ignores Follow-Up and Chooses Wrong Spline Josenildo 7 4,467 07-29-2025, 09:15 PM
Last Post: _Aka_

Forum Jump: