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
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 14 03-04-2024, 11:06 AM
Last Post: _Aka_

Forum Jump: