Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to detect bend in a spline or strait part of spline at position
#8
I used 2 variables for storing tangents during Update method

private Vector3 previousTangent=Vector3.zero;
private Vector3 currentTangent=Vector3.zero;

and in Update:
// Check if we have current tangent and set as previous
if (currentTangent!=Vector3.zero)
{
previousTangent = currentTangent;
}
// Angle on Z axis to lean object on rail
sideLean = (Vector3.Angle(currentTangent - previousTangent, transform.forward) - 90) * (Speed/MaxSpeed)*MaxLeanFactor;
// Apply lean angle
this.gameObject.transform.localRotation = Quaternion.Euler(0, 0, sideLean);

Speed is current speed of object on rail
MaxSpeed is maximum speed on rail
MaxLeanFactor is factor for making lean more or less

I'm not sure if that's working correctly since I discarded that feature.
Reply


Messages In This Thread
RE: How to detect bend in a spline or strait part of spline at position - by velikizlivuk - 08-13-2023, 06:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Best way to duplicate a spline with an offset Kapistijn 8 1,289 04-12-2026, 03:18 PM
Last Post: _Aka_
Smile Constant speed along a spline? tfishell 1 644 11-13-2025, 11:32 AM
Last Post: _Aka_
  SplineController Ignores Follow-Up and Chooses Wrong Spline Josenildo 7 4,429 07-29-2025, 09:15 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 7 6,163 07-13-2025, 07:11 PM
Last Post: _Aka_

Forum Jump: