12-21-2023, 04:54 AM

For a while I have been using this code to measure cornering lean

it was working really well until recently when I realised it was giving me terrible results on splines that aren't totally flat on the xz plane.

So much so that I drew the tangent lines with this to debug

Added some pictures below - the tangent lines give a really beautiful almost perpendicular tangent against the spline when the spline is flat as you would expect.

As soon as the spline goes even slightly up or down then the tangents shoot off together wildly to the left or right. What could be causing this?

Code:

` //CORNERING LEAN`

float BikeTFDistance = Spline.TFToDistance(BikeTF, CurvyClamping.Clamp);

Vector3 Cornerbehind = Spline.GetTangentByDistance(BikeTFDistance - 0.5f,Space.World);

Vector3 Cornercomingup = Spline.GetTangentByDistance(BikeTFDistance + 0.5f, Space.World);

Cornerbehind.y = 0;

Cornercomingup.y = 0;

newcornerangle = Vector3.SignedAngle(Cornerbehind, Cornercomingup, Vector3.up);

delta = newcornerangle - lastcornerangle;

delta *= Time.deltaTime;

lastcornerangle += delta;

it was working really well until recently when I realised it was giving me terrible results on splines that aren't totally flat on the xz plane.

So much so that I drew the tangent lines with this to debug

Code:

` float linelength = 5f;`

Debug.DrawLine(mRigidBody.transform.position, mRigidBody.transform.position + Cornerbehind.normalized * linelength, Color.blue, 0.01f);

Debug.DrawLine(mRigidBody.transform.position, mRigidBody.transform.position + Cornercomingup.normalized * linelength, Color.red, 0.01f);

Added some pictures below - the tangent lines give a really beautiful almost perpendicular tangent against the spline when the spline is flat as you would expect.

As soon as the spline goes even slightly up or down then the tangents shoot off together wildly to the left or right. What could be causing this?