private void Play() { float m = (rail.nodes [currentSeg + 1].position - rail.nodes [currentSeg].position).magnitude; float s = (Time.deltaTime * 1 / m) * moveSpeed; transition += s; if (transition > 1) { transition = 0; currentSeg++; if (currentSeg == rail.nodes.Length - 1) { if (loop) { currentSeg = 0; } else { isCompleted = true; return; } } } else if (transition < 0) { transition = 1; currentSeg--; } transform.position = rail.PositionOnRail(currentSeg, transition, mode, rail.path); if (!VRMode) { transform.rotation = rail.Orientation(currentSeg, transition); } }
public void Play() { movement.enabled = false; //horizontalMovement.enabled = false; if (stateManager.currentState != PlayerStateManager.PlayerState.Grinding) { stateManager.ActiveState(PlayerStateManager.PlayerState.Grinding); } speed = movement.speed / railBraking; float magnitude = (rail.nodes[currentSegment + 1].position - rail.nodes[currentSegment].position).magnitude; float normalizedSpeed = (Time.deltaTime * 1 / magnitude) * speed; transition += normalizedSpeed; if (transition > 1) { transition = 0; currentSegment++; if (currentSegment == rail.nodes.Length - 1) { isCompleted = true; movement.enabled = true; //horizontalMovement.enabled = true; stateManager.ActiveState(PlayerStateManager.PlayerState.Airborne); transform.rotation = initialRotation; start = false; currentSegment = 0; comboManager.newComboValue = 1; comboManager.AddToCombo(); return; } } else if (transition < 0) { transition = 1; currentSegment--; } transform.position = rail.PositionOnRail(currentSegment, transition, mode); //transform.rotation = rail.Orientation(currentSegment, transition); }
private void Play() { transition += Time.deltaTime * 1 / 2.5f; if (transition > 1) { transition = 0; currentSeg++; } if (currentSeg + 1 == rail.Length) { isCompleted = true; } else { transform.position = rail.PositionOnRail(currentSeg, transition, playMode); transform.rotation = rail.Orientation(currentSeg, transition); } }
private void Play(bool forward = true) { //calculate speed and stuff var temp = rail.nodes.Length; float m = (rail.nodes[currentSeg + 1].position - rail.nodes[currentSeg].position).magnitude; float s = (Time.deltaTime * 1 / m) * speed; transition += (forward) ? s : -s; //check transition if (transition > 1) { transition = 0; currentSeg++; //if we reached the end if (currentSeg == rail.nodes.Length - 1) { finishedRoute = true; isStopped = true; return; } } else if (transition < 0) { transition = 1; currentSeg--; if (currentSeg == -1) { isStopped = true; return; } } transform.position = rail.PositionOnRail(currentSeg, transition, mode, grounded); transform.rotation = rail.Orientation(currentSeg, transition); }
private void Play(bool forward = true) { float m = (rail.nodes[currentSeg + 1].position - rail.nodes[currentSeg].position).magnitude; float s = (Time.deltaTime * 1 / m) * speed; transition += (forward) ? s : -s; if (transition > 1) { transition = 0; currentSeg++; if (currentSeg == rail.nodes.Length - 1) { if (isLooping) { if (pingPong) { transition = 1; currentSeg = rail.nodes.Length - 2; isReversed = !isReversed; } else { currentSeg = 0; } } else { isCompleted = true; return; } } } else if (transition < 0) { transition = 1; currentSeg--; if (currentSeg == -1) { if (isLooping) { if (pingPong) { transition = 0; currentSeg = 0; isReversed = !isReversed; } else { currentSeg = rail.nodes.Length - 2; } } else { isCompleted = true; return; } } } transform.position = rail.PositionOnRail(currentSeg, transition, mode); transform.rotation = rail.Orientation(currentSeg, transition); }
private void Play(bool forward = true) { float m = (rail.nodes[currentIndex + 1].position - rail.nodes[currentIndex].position).magnitude; float s = (Time.deltaTime * 1 / m) * speed; dot += (forward) ? s : -s; if (dot > 1) { dot = 0.0f; currentIndex++; if (currentIndex == rail.nodes.Length - 1) { if (isLooping) { if (pingPong) { dot = 1; currentIndex = rail.nodes.Length - 2; isReversed = !isReversed; } else { currentIndex = 0; } } else { isCompleted = true; return; } } } else if (dot < 0) { dot = 1; currentIndex--; if (currentIndex == -1) { if (isLooping) { if (pingPong) { dot = 0; currentIndex = 0; isReversed = !isReversed; } else { currentIndex = rail.nodes.Length - 2; } } else { isCompleted = true; return; } } } transform.position = rail.PositionOnRail(currentIndex, dot, mode); transform.rotation = rail.Orientation(currentIndex, dot); }
private void Move() { if (Time.timeScale == 0) { return; } TransitionPoint tp = rail.nodes[currentNodeIndex].gameObject.GetComponent <TransitionPoint>(); RailTrigger[] rts = tp.getRailTriggers(); if (rts.Length > 0) { foreach (RailTrigger rt in rts) { if (!rt.activated) { if (rt.onEnter) { rt.Activate(); } } } } // Does this TP have requirements before we can move? if (!tp.metRequirements()) { return; // If we haven't met the requirements, do not move } if (Camera.main.GetComponent <CameraCollider>().EnemiesNearby()) { lastEnemyTime = Time.time; return; // Don't do anything if enemies nearby } else { if ((Time.time - lastEnemyTime) < ENEMY_KILLED_DELAY) { return; } } int targetIndex = (tp.targetPoint != null) ? tp.targetPoint.gameObject.GetComponent <TransitionPoint>().index : currentNodeIndex + 1; if (targetIndex >= rail.nodes.Count) // We are on the last node // We've reached the end { isCompleted = true; return; } Vector3 targetPosition = rail.nodes[targetIndex].position; Quaternion targetRotation = rail.nodes[targetIndex].rotation; // We have met all requirements, we can move // The magnitude of the next TP and the current one float mP = (targetPosition - rail.nodes[currentNodeIndex].position).magnitude; // The point on the segment that we are on, based on the speed of the TP float sP = (Time.deltaTime * 1 / mP) * tp.transitionSpeed; transitionPosition += sP; float mQ = Quaternion.Angle(targetRotation, rail.nodes[currentNodeIndex].rotation); float sQ = (Time.deltaTime * 1 / mQ) * (tp.transitionSpeed * 10); transitionQuaternion += sQ; if ((transitionPosition >= 1 && transitionQuaternion >= 1) || (transitionPosition == Mathf.Infinity && transitionQuaternion == Mathf.Infinity)) // If we are moving forwards and reached our destination { if (rts.Length > 0) { foreach (RailTrigger rt in rts) { if (!rt.activated) { if (!rt.onEnter) { rt.Activate(); } } } } transitionPosition = 0; // set the point on the line back to the beginning transitionQuaternion = 0; if (tp.targetPoint == null) { currentNodeIndex++; // Just go to the next segment } else { currentNodeIndex = tp.targetPoint.gameObject.GetComponent <TransitionPoint>().index; } if (currentNodeIndex == rail.nodes.Count) // If we are on the last node { if (tp.targetPoint == null) { isCompleted = true; return; } else { currentNodeIndex = tp.targetPoint.gameObject.GetComponent <TransitionPoint>().index; } } } // Move us transform.position = rail.PositionOnRail(currentNodeIndex, targetIndex, transitionPosition, mode); transform.rotation = rail.Orientation(currentNodeIndex, targetIndex, transitionQuaternion); }
/// <summary> /// Plays the movement to follow the path. /// </summary> /// <param name="forward"> A boolean to make it go forward or backwards.</param> private void Play(bool forward = true) { switch (speedMode) // Choose between using speed or time { default: case SpeedMode.ConstantSpeed: // Make it to move at a constant speed on every node float m = (rail.nodes[currentSeg + 1].position - rail.nodes[currentSeg].position).magnitude; float s = (Time.deltaTime * 1 / m) * speed; transition += (forward) ? s : -s; break; case SpeedMode.TimeBetweenSegments: // Make the object to reach next node in timeBetweenSegments float move = Time.deltaTime * 1 / timeBetweenSegments; transition += (forward) ? move : -move; break; } if (transition > 1 && !loopNode) // Already reached next segment and it doesn't want to loop over same node. { transition = 0; // Restart the count. currentSeg++; // Update the segment it is in. if (currentSeg == rail.nodes.Length - 1) // Last segment reached. { if (isLooping) // If it is looping start again or play it backwards (pingPong). { if (pingPong) { transition = 1; currentSeg = rail.nodes.Length - 2; isReversed = !isReversed; } else { currentSeg = 0; } } else { isCompleted = true; } } } else if (transition > 1 && loopNode) // Already reached next segment and want to loop over same node. { transition = 0; // Restart the count. } else if (transition < 0 && !loopNode) // Same logic that before but backwards, reached next segment and it doesn't want to loop over same node. { transition = 1; // Restart the count. currentSeg--; // Update the segment it is in. if (currentSeg == -1) // Last segment reached. { if (isLooping) // If it is looping start again or play it backwards (pingPong). { if (pingPong) { transition = 0; currentSeg = 0; isReversed = !isReversed; } else { currentSeg = rail.nodes.Length - 2; } } } } else if (transition < 0 && loopNode) // Same logic that before but backwards, reached next segment and it wants to loop over same node. { transition = 1; // Restart the count } // Update position and orientation. if (playMode != PlayMode.Catmull || currentSeg < rail.nodes.Length - 1) { transform.position = rail.PositionOnRail(currentSeg, transition, playMode); } if (orientationMode != OrientationMode.None) { transform.rotation = rail.OrientationOnRail(currentSeg, transition, orientationMode, transform, isReversed); } }