Re: [MOD 0.17] VehicleSnap

Yeah you can set a line towards a goal, but what if you predicted the orientation wrong initially? It's quite an odd angle there requiring arctan()

Ok, if for some reason arctg() usage looks unclear, another approach can be taken.
These half-diagonal lines have pretty simple equations: y = k*x + b, where k is either +-0.5 or +-2.
It's just school geometry math, without arctg().
Simple auto-correction is required for a car to move exactly along these lines.
If car is too left from the line - increase its orientation to try to return it back to the line.
If car is too right from the line - decrease its orientation.
If orientation is too far form the target line - stop trying to correct it (it means user is changing the orientation manually).
So, all the calculations required:
- determine coefficients of the line equation on snapping start,
- calculate the distance between the current car position and the point the car must be now on the target line,
- apply "returning-to-line" force to the car, the longer the distance the stronger the returning force.
It looks pretty doable. No arctg() is required.
All you need to know about this "odd angle" is it is approximately 0.074 +- 0.001. Such low precision is more than enough to decide which angle we are now snapping to.
Statistics: Posted by Egor — Fri Apr 10, 2026 1:36 am