07-15-2021, 04:39 PM
Hey
thanks for the fast answer.
here is the code. Most of it is from the demo.
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);
}
}