Posts: 3
Threads: 2
Joined: May 2021
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?
Posts: 2,063
Threads: 88
Joined: Jun 2017
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.
Posts: 3
Threads: 2
Joined: May 2021
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);
}
}
Posts: 2,063
Threads: 88
Joined: Jun 2017
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.
Posts: 2,063
Threads: 88
Joined: Jun 2017
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.