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

We have multiple tiles, each with 3 splines (left lane,middle lane,right lane)
The player walks on one spline and he can change the lane (typical endlessrunner)
While the player walks, new tiles appear and old ones get removed.Now here is our problem. If the player switches the spline/lane at the end of one tile
(where the splines of the current tile end and the splines of the new tiles begin),
the player gets stuck/doesn't move forward because he has the wrong controlpoint.


if the player dont switch the lane at the end of a tile all things works 


any idea how i can fix that?
Reply
#2
Hi
Can you send me the code that does the switching?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#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
#4
Thanks
I didn't have the time to check this today. I will do tomorrow. Sorry for the delay and have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Hi
Is your controller set to update in Update or in another update (fixed or late)? If not set, please try setting it to Update and see if it changes the situation.

Other than that, I recommand you to log for every frame the controller's spline, IsSwitching, SwitchProgress, mSwitchInProgress, mPossibleSwitchTarget and the events OnControlPointReached, OnEndReached, and OnSwitch, and see what goes wrong when player reaches the end of a spline. It is a lot of logs to see, but normally you would only have to check their values for fews frames before or after the switch to pinpoint what is wrong.

I hope this helps
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Locking the UV's of a closed spline John_MLS 1 105 07-09-2021, 03:54 PM
Last Post: _Aka_
  Accessing generator's input spline in script, changing it at runtime smackledorf 3 277 06-17-2021, 01:59 PM
Last Post: _Aka_
  Questions about Generator: mesh/objects within spline, snap to control point dartboard 5 442 06-09-2021, 12:42 PM
Last Post: _Aka_
  get world vector3 from absolute position on spline hawken 2 246 06-08-2021, 12:28 PM
Last Post: hawken

Forum Jump: