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
  Getting Distance from a World Point zorksox 3 5 04-16-2024, 07:30 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_

Forum Jump: