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
  Spline Issue Leading to Unity Freeze Pankaj09 1 329 08-24-2026, 11:28 PM
Last Post: _Aka_
  Connecting Multiple Spline Nodes Issue Ritesh Kadam 1 285 08-22-2026, 11:24 PM
Last Post: _Aka_
  Spline Spots from 2 samples. BitBlit 8 1,351 06-30-2026, 11:49 AM
Last Post: _Aka_
  Best way to duplicate a spline with an offset Kapistijn 8 2,754 04-12-2026, 03:18 PM
Last Post: _Aka_

Forum Jump: