11-20-2024, 02:38 PM
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
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:
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:
Thanks in advance !
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
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 !

