Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
player stuck on spline
#3
Hey 

thanks for the fast answer. 

here is the code. Most of it is from the demo.


Code:
    override protected void InitializedApplyDeltaTime(float deltaTime)     {         // If allowed to switch and player wants to, initiate switching         // -1 left | 0 no | 1 right         if (mPossibleSwitchTarget != null && mSwitchInProgress == 0)         {             //CONTROLLS FOR PC             if(Input.GetKeyDown(KeyCode.A))             {                 //Move nach Links                 Switch(-1);             }             else if (Input.GetKeyDown(KeyCode.D))             {                 //Move nach Rechts                 Switch(1);             } }         else if(mSwitchInProgress != 0 && !IsSwitching)         {             mSwitchInProgress = 0;             OnCPReached(new CurvySplineMoveEventArgs(this, Spline, Spline.TFToSegment(RelativePosition), 0, false, 0, MovementDirection.Forward));         }         base.InitializedApplyDeltaTime(deltaTime);             }


Code:
void Switch(int dir)     {         if(dir == 0 || (currentPath == PathDir.Left && dir == -1) || (currentPath == PathDir.Right && dir == 1))         {             return;         }         mSwitchInProgress = dir;         Vector3 posInTargetSpace;         Vector3 nearestPoint;         float nearestPointTF;         CurvySpline targetSpline = dir == -1 ? mPossibleSwitchTarget.leftNeighborSpline : mPossibleSwitchTarget.rightNeighborSpline;         CurvySplineSegment targetCP = dir == -1 ? mPossibleSwitchTarget.leftNeighborCP : mPossibleSwitchTarget.rightNeighborCP;         currentPath += dir;         posInTargetSpace = targetSpline.transform.InverseTransformPoint(transform.position);         nearestPointTF = targetSpline.GetNearestPointTF(posInTargetSpace, out nearestPoint, targetCP.Spline.GetSegmentIndex(targetCP));               float swSpeed = (nearestPoint - posInTargetSpace).magnitude / Speed;         SwitchTo(targetSpline, nearestPointTF, swSpeed);         return;     }


Code:
// Retrieve switch metadata     public void OnCPReached(CurvySplineMoveEventArgs e)     {         mPossibleSwitchTarget = e.ControlPoint.GetMetadata<SplineSwitchData>();         // if not properly configured, ignore!         if (mPossibleSwitchTarget && !mPossibleSwitchTarget.Spline)             mPossibleSwitchTarget = null;     }     //Start falling when reaching the start of new spline that is not a Follow-Up     public void UseFollowUpOrFall(CurvySplineMoveEventArgs e)     {         CurvySplineSegment controlPoint = e.ControlPoint;         if (controlPoint == e.Spline.FirstVisibleControlPoint && controlPoint.Connection && controlPoint.FollowUp == false)         {             float deltaY = controlPoint.transform.position.y - controlPoint.Connection.OtherControlPoints(controlPoint)[0].transform.position.y;             OffsetRadius += Mathf.Abs(deltaY);         }     }
Reply


Messages In This Thread
player stuck on spline - by Dextex - 07-15-2021, 01:14 PM
RE: player stuck on spline - by _Aka_ - 07-15-2021, 04:32 PM
RE: player stuck on spline - by Dextex - 07-15-2021, 04:39 PM
RE: player stuck on spline - by _Aka_ - 07-16-2021, 10:44 PM
RE: player stuck on spline - by _Aka_ - 07-17-2021, 04:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Spline Issue Leading to Unity Freeze Pankaj09 1 423 08-24-2026, 11:28 PM
Last Post: _Aka_
  Connecting Multiple Spline Nodes Issue Ritesh Kadam 1 367 08-22-2026, 11:24 PM
Last Post: _Aka_
  Spline Spots from 2 samples. BitBlit 8 1,521 06-30-2026, 11:49 AM
Last Post: _Aka_
  Best way to duplicate a spline with an offset Kapistijn 8 2,932 04-12-2026, 03:18 PM
Last Post: _Aka_

Forum Jump: