Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue Keeping Rigidbody Player Following Spline
#1
Question 
With Curvy 1.6 I used the following code to keep my custom rigidbody controller aligned to a spline in the X axis.

Code:
Vector3 splinePosition = Spline.Interpolate(TF);
// Bring the player back onto the spline if they drift from it i.e. running round curves etc.
Vector3 offset = new Vector3(transform.position.x - splinePosition.x, 0, 0);
if (offset.sqrMagnitude > 0.001f)
{
    transform.position -= offset.normalized * Time.deltaTime;
}

However after upgrading to Curvy 2, this code no longer functions as expected. The controller follows the overall shape of the spline, but is not aligned to it i.e. following along on top of the tangents/curve.

I assume that my approach is now outdated in Curvy 2, but i am at a loss as to work out how to upgrade it. 

So if anyone has any hints/suggestions, I'd appreciate the assistance.
Reply
#2
Unlike in 1.61, Spline's return local coordinates in Curvy 2, so this may be a reason why it fails now. You may also want to have a look at the two rigidbody examples provided and see how we used custom controllers to deal with Rigidbodies.
Reply
#3
(12-23-2015, 02:11 PM)Jake Wrote: Unlike in 1.61, Spline's return local coordinates in Curvy 2, so this may be a reason why it fails now. You may also want to have a look at the two rigidbody examples provided and see how we used custom controllers to deal with Rigidbodies.

Thanks for the reply. By looking through the example code/scenes with the knowledge that splines return local space co-ordinates, I've been able to re-implement the original behaviour in the Curvy 2 version of my rigidbody controller  Big Grin .
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Brick Delete CurvySplineSegment from the start of a Spline causes UV's to change studentloan 5 6 06-14-2022, 03:14 PM
Last Post: _Aka_
  Obstacle Moving Along the spline Chanon 1 5 06-13-2022, 04:13 PM
Last Post: _Aka_
Information Common reasons why your spline gizmo is invisble _Aka_ 0 1 05-20-2022, 03:56 PM
Last Post: _Aka_
  Connect two spline at runtime Doomchecker 2 7 05-18-2022, 04:12 PM
Last Post: Doomchecker

Forum Jump: