Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Angle detection by tangent
#1
Hello ! First of all thanks for this package, i really enjoy working with it Smile 

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();
3. Then finally i can compute my curvature
Code:
// Calculate curvature strength by the angle between current and future tangents.
float xzCurvatureAngle = Vector3.Angle(currentTangent, aheadTangent);
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 !


Attached Files Thumbnail(s)
       
Reply


Messages In This Thread
Angle detection by tangent - by Skuuulzy - 11-18-2024, 11:31 AM
RE: Angle detection by tangent - by _Aka_ - 11-18-2024, 04:30 PM
RE: Angle detection by tangent - by Skuuulzy - 11-20-2024, 02:38 PM
RE: Angle detection by tangent - by Skuuulzy - 11-20-2024, 03:59 PM
RE: Angle detection by tangent - by _Aka_ - 11-21-2024, 08:40 AM
RE: Angle detection by tangent - by Skuuulzy - 11-21-2024, 02:38 PM
RE: Angle detection by tangent - by _Aka_ - 11-22-2024, 10:47 AM
RE: Angle detection by tangent - by Skuuulzy - 11-27-2024, 01:20 PM
RE: Angle detection by tangent - by _Aka_ - 11-28-2024, 09:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Corner Angle Revisited SAMYTHEBIGJUICY 10 6,134 01-02-2024, 10:12 AM
Last Post: _Aka_
  How can I find the point on the spline after applying with offset angle+radius? Chanon 1 1,443 10-01-2022, 11:50 AM
Last Post: _Aka_
  Tangent incorrect. tairoark 3 2,516 06-28-2022, 06:31 PM
Last Post: _Aka_
  Make hard angle cll3m 5 4,343 07-01-2021, 04:06 PM
Last Post: _Aka_

Forum Jump: