11-18-2024, 11:31 AM
Hello ! First of all thanks for this package, i really enjoy working with it
So i'm currently working on a game of slot car were i want to give a fake drift to my spline follower (by rotating the view) based on the curvature of the spline. So i'm building a CustomSplineController that inherits from SplineController
To get the curvature of the spline i use the following approach:
1. Get 2 tangent
2. I want to ignore my vertical variation because I'm only interested in the XZ curvature angle
3. Then finally i can compute my curvature
I'm pretty happy with this approach it's works very well when there is no vertical curvature in my spline (when the Y component of my tangent are 0 or near 0) in a standard flat turn.
However, when the splines exhibit vertical variation in the Y direction, the xzCurvatureAngle is significantly larger than it should be. It happen when the car take a looping for example.
My first thought is that my approach to flatten the tangent is not functional.
Do you have maybe an idea why ? Or a better approach to determine the XZ Curvature Angle of a spline ?
Also the physic in a looping become very complicated so maybe I'm not taking in account an inversion of sign in one the tangent component ? I'm not sure I'm a bit overwhelmed here ^^
PS: The red sphere in front of the car in the pictures is the ahead tracker (relativePosition + _normalizedAheadOffset).
Thanks in advance, great day to you !

So i'm currently working on a game of slot car were i want to give a fake drift to my spline follower (by rotating the view) based on the curvature of the spline. So i'm building a CustomSplineController that inherits from SplineController
To get the curvature of the spline i use the following approach:
1. Get 2 tangent
Code:
Vector3 currentTangent = GetTangent(relativePosition);
Vector3 aheadTangent = GetTangent(relativePosition + _normalizedAheadOffset); // Small offset ahead for curvature approximation
2. I want to ignore my vertical variation because I'm only interested in the XZ curvature angle
Code:
// Flatten tangents by setting the y-component to zero, ignoring vertical variations.
currentTangent.y = 0;
aheadTangent.y = 0;
// Re-normalize the vectors to prevent any magnitude issues after zeroing out y.
currentTangent.Normalize();
aheadTangent.Normalize();
Code:
// Calculate curvature strength by the angle between current and future tangents.
float xzCurvatureAngle = Vector3.Angle(currentTangent, aheadTangent);
However, when the splines exhibit vertical variation in the Y direction, the xzCurvatureAngle is significantly larger than it should be. It happen when the car take a looping for example.
My first thought is that my approach to flatten the tangent is not functional.
Do you have maybe an idea why ? Or a better approach to determine the XZ Curvature Angle of a spline ?
Also the physic in a looping become very complicated so maybe I'm not taking in account an inversion of sign in one the tangent component ? I'm not sure I'm a bit overwhelmed here ^^
PS: The red sphere in front of the car in the pictures is the ahead tracker (relativePosition + _normalizedAheadOffset).
Thanks in advance, great day to you !