Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Angle detection by tangent
#3
Hello thanks for your answer !

Yes it take inspiration from Slot Car race ! For now it's only a small prototype, but if it goes further i can keep you updated Smile 

So, I've tried to change my code using your approach sadly the result is not has expected.

First of all I'm not so sure that the projection on the spline normal was a good idea. No matter what i get the same results without the projection.

So here's my updated code using SignedAngle wich I agree with is more adapted to the situation:

Code:
        // Get current and future tangents on the spline to estimate curvature
        Vector3 currentTangent = GetTangent(relativePosition);
       
        _normalizedAheadOffset = (200 * _aheadTangentOffset) / Spline.Length;
        _aheadRelativePosition = relativePosition + _normalizedAheadOffset;
        _aheadTarget.RelativePosition = _aheadRelativePosition;
       
        Vector3 aheadTangent = GetTangent(relativePosition + _normalizedAheadOffset); // Small offset ahead for curvature approximation
       
        // For inspector debug purpose
        _tangent = currentTangent;
        _aheadTangent = aheadTangent;

        if (_projectTangentOnSpline)
        {
            // Ignoring vertical variations by projecting the tangent on a plane which normal is the spline's orientation.
            currentTangent = Vector3.Project(currentTangent, Spline.GetOrientationUpFast(relativePosition));
            aheadTangent = Vector3.Project(aheadTangent, Spline.GetOrientationUpFast(relativePosition + _normalizedAheadOffset));
        }
       
        // Calculate curvature strength by the angle between current and future tangents.
        float xzCurvatureAngle = Vector3.SignedAngle(currentTangent, aheadTangent, transform.up);
       
        // For inspector debug purpose
        _XZCurvatureAngle = xzCurvatureAngle;
        _XYCurvatureAngle = Vector3.SignedAngle(currentTangent, aheadTangent, transform.forward);
        _YZCurvatureAngle = Vector3.SignedAngle(currentTangent, aheadTangent, transform.right);

As you can see i compute the angles based on the local axis of my follower. So i expect to have different value for the different curvature angle.

In the screenshots bellow i have the same value for all my angle, and this value is the ZY angle that you can see in this picture.    

But the XZ angle that can be view in this picture is not correctly computed.    

I really don't understand what i do wrong here. Do you see why all my curvature angle are equal to the ZY angle ?

For reference this is the code i use for drawing the rays:

Code:
    private void OnDrawGizmos()
    {
        DrawDirectionArrow(transform.position, GetTangent(RelativePosition) * 5, Color.red);
        DrawDirectionArrow(transform.position, GetTangent(RelativePosition + _normalizedAheadOffset) * 5, Color.green);
    }

    private void DrawDirectionArrow(Vector3 start, Vector3 direction, Color color)
    {
        Gizmos.color = color;

        // Draw the ray
        Gizmos.DrawRay(start, direction);
        Gizmos.DrawWireSphere(start + direction, 0.2f);
    }

Thanks in advance !
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: