Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stack Overflow
#8
(01-10-2014, 05:33 PM)'Jake' Wrote: Ok, what exactly are you doing? You're using the SplineWalkerCon (or your own script calling MoveConnection) to travel along several connected splines, right? How are that splines connected? If you can't provide an example scene, perhaps you can post some screenshots (you can also pm them)...


 
As I said, i use the EndlessRunnerPlayer, modified with my needs : 





Code:
void Update () {
if (!waitToStartComplete || !Spline || !Spline.IsInitialized || avatarController.IsDead)
return;

// *** Place Player in editor ***
if (!Application.isPlaying) {
if (Spline.Interpolate(TF)!=mTransform.position)
mTransform.position = Spline.Interpolate(TF);
return;
}

int dir=1;

// advance on lane. We use PingPong clamping to detect when we reach the end of a spline (in that case dir changes!)
Vector3 newPosOnSpline = Spline.MoveByConnection(ref Spline, ref TF, ref dir, Speed * Time.deltaTime, CurvyClamping.PingPong, 0, tags);
Vector3 newTangent = Spline.GetTangent(TF);

// Advance by spline curvation delta. We don't use newPosOnSpline directly because we don't want a snap-effect when in air or switching lanes
mTransform.position += newPosOnSpline - mLastPosOnSpline;

currentLanePosition = Spline.Interpolate(TF);

if(startRun) {
// *** Switch lanes? ***
if(avatarController.CanSwitchLane()) {
if(TrySwitchLane(inputManager.HorizontalRawDir * mTransform.right)) {
avatarController.SwitchLaneCooldown();
avatarController.StartCoroutine("PlaySwitchLane");
if(!avatarController.IsInTheAir()) {
if(!avatarController.IsSliding()) {
avatarController.PlayAnim(inputManager.HorizontalRawDir > 0 ? "R-switch" : "L-switch", "run");
}
}
currentLanePosition = Spline.Interpolate(TF);
//Debug.Log("new spline : " + Spline.gameObject.name);
newPosOnSpline = currentLanePosition;
}
}

// *** Jump? ***
if(avatarController.CanJump()) {
avatarController.Jump();
}

// *** Slide ? ***
if(avatarController.CanSlide()) {
avatarController.Slides();
}

if(avatarController.CanDash()) {
avatarController.Dash();
}

// Set orientation
mTransform.forward = newTangent;
if(SetOrientation) {
transform.rotation = Spline.GetOrientationFast(TF);
}
}

if(dir != 1) {
//Debug.Log("die ? ");
StopsRunningAndMeetObstacle();
avatarController.CurrentAvatar.animPool.Stop("run");
}


Vector3 offset = mTransform.position - newPosOnSpline;

// When in air or switching lanes, our position isn't where it should be. So we drag the player toward the lane position
if(!avatarController.IsJumping()) {
if(offset.sqrMagnitude > 0.02f) {
if(avatarController.IsInTheAir()) {
if(avatarController.CanFall()) {
avatarController.Fall();
}

mTransform.Translate(avatarController.GetFallOffset(), Space.World);

if(offset.sqrMagnitude > 0.02f) {
mTransform.position -= new Vector3(offset.x * SwitchSpeed * Time.deltaTime, 0, 0);
}
} else {
avatarController.IsSwitchingLane = true;
mTransform.position -= offset * SwitchSpeed * Time.deltaTime;
}
} else{
avatarController.IsSwitchingLane = false;
if(avatarController.CanLand()) {
avatarController.Land();
}
if(avatarController.IsFallingTowardsHole()) {
avatarController.SetInAir(true);
mTransform.Translate(avatarController.GetFallOffset(), Space.World);
} else {
avatarController.SetInAir(false);
}
}
}else { // Perform a jump
//if set to Space.Self, do shit about xPos... (slight offest when jumping, dafuq...)
mTransform.Translate(avatarController.GetJumpOffset(), Space.World);
if(offset.sqrMagnitude > 0.02f) {
mTransform.position -= new Vector3(offset.x * SwitchSpeed * Time.deltaTime, 0, 0);
}

mLastPosOnSpline = mTransform.position;
}

mLastPosOnSpline = newPosOnSpline;
}




Here are some screenshots of my game, : i have lanes (3 lanes most of the time) :

[Image: screen01.png]


[Image: screen02.png]

 
Reply


Messages In This Thread
Stack Overflow - by lelag - 12-18-2013, 10:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Stack overflow when editing prefab containing splines rhys_vdw 5 24 04-10-2023, 10:17 PM
Last Post: _Aka_

Forum Jump: