internal static void DrawPathGizmos(CinemachinePath path, GizmoType selectionType) { // Draw the path Color colorOld = Gizmos.color; Gizmos.color = (Selection.activeGameObject == path.gameObject) ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor; float step = 1f / path.m_Appearance.steps; Vector3 lastPos = path.EvaluatePosition(path.MinPos); Vector3 lastW = (path.EvaluateOrientation(path.MinPos) * Vector3.right) * path.m_Appearance.width / 2; for (float t = path.MinPos + step; t <= path.MaxPos + step / 2; t += step) { Vector3 p = path.EvaluatePosition(t); Vector3 w = (path.EvaluateOrientation(t) * Vector3.right) * path.m_Appearance.width / 2; Vector3 w2 = w * 1.2f; Vector3 p0 = p - w2; Vector3 p1 = p + w2; Gizmos.DrawLine(p0, p1); Gizmos.DrawLine(lastPos - lastW, p - w); Gizmos.DrawLine(lastPos + lastW, p + w); lastPos = p; lastW = w; } Gizmos.color = colorOld; }
public IEnumerator SwitchPosition(Vector3 newPosition, CinemachinePath newTrack, int waypointIndex, float transitionSpeed, GameObject target, bool isDelayRng, float Maxdelay) { showDirector.GetComponent <CinemachineDollyCart>().m_Path = null; isSetup = false; focus = target; yield return(new WaitUntil(() => { transform.position = Vector3.SmoothDamp(transform.position, newPosition, ref zero, 0.5f, transitionSpeed); showDirector.transform.position = Vector3.Slerp(showDirector.transform.position, transform.position, 2.0f * Time.deltaTime); return Vector3.Distance(transform.position, newPosition) <= 0.1f; })); isSetup = true; speed = 0.5f; showDirector.GetComponent <CinemachineDollyCart>().m_Path = newTrack; showDirector.GetComponent <CinemachineDollyCart>().m_Position = waypointIndex; if (isDelayRng) { float rngDelay = Random.Range(4.0f, Maxdelay); currentCoroutine = StartCoroutine(DelayUntilNextPosition(rngDelay)); } else { currentCoroutine = StartCoroutine(DelayUntilNextPosition(Maxdelay)); } }
public void StartCoroutineSwitchPosition(Vector3 newPosition, CinemachinePath newTrack, int waypointIndex, float transitionSpeed, GameObject target, bool isDelayRng, float Maxdelay) { if (currentCoroutine != null) { StopCoroutine(currentCoroutine); } currentCoroutine = StartCoroutine(SwitchPosition(newPosition, newTrack, waypointIndex, transitionSpeed, target, isDelayRng, Maxdelay)); }
public void StartCoroutineSwitchToDeadPlayer(Vector3 newPosition, CinemachinePath newTrack, float transitionSpeed, GameObject target, float Maxdelay, bool deadByFall) { if (currentCoroutine != null) { StopCoroutine(currentCoroutine); } currentCoroutine = StartCoroutine(SwitchToDeadPlayer(newPosition, newTrack, transitionSpeed, target, Maxdelay, deadByFall)); }
public void SetNextLoop(CinemachinePath pathLink, CinemachinePath path, int swap, int start) { nextPathLink = pathLink; nextPath = path; currentSwitchPoint = swap; nextStartPoint = start; state = CartState.Linked; CalculatePathLink(); }
public IEnumerator SwitchToDeadPlayer(Vector3 newPosition, CinemachinePath newTrack, float transitionSpeed, GameObject target, float Maxdelay, bool deadByFall) { showDirector.GetComponent <CinemachineDollyCart>().m_Path = null; isSetup = false; focus = target; yield return(new WaitUntil(() => { if (!deadByFall) { if (Vector3.Distance(transform.position, newPosition) <= 5.0f) { newPosition = transform.position; } //Director translation to position itself if (transform.position.y <= 4.5f) { transform.position = new Vector3(transform.position.x, 4.5f, transform.position.z); } } else { Vector3 positionAbove = new Vector3(target.transform.position.x, 10.0f, target.transform.position.z); newPosition = positionAbove; if (Vector3.Distance(transform.position, positionAbove) <= 5.0f) { newPosition = transform.position; } } transform.position = Vector3.SmoothDamp(transform.position, newPosition, ref zero, 0.5f, transitionSpeed); showDirector.transform.position = Vector3.Slerp(showDirector.transform.position, transform.position, 2.0f * Time.deltaTime); //Death Track rotation to face player dead body Vector3 lookPos = target.transform.position - tracksEvent[2].transform.position; lookPos.y = 0; Quaternion rotation = Quaternion.LookRotation(lookPos); tracksEvent[2].transform.rotation = Quaternion.Slerp(tracksEvent[2].transform.rotation, rotation, 1.0f); return Vector3.Distance(transform.position, newPosition) <= 0.1f; })); isSetup = true; speed = 1.0f; showDirector.GetComponent <CinemachineDollyCart>().m_Path = newTrack; showDirector.GetComponent <CinemachineDollyCart>().m_Position = 0.0f; currentCoroutine = StartCoroutine(DelayUntilNextPosition(Maxdelay)); }
private static void DrawTrackeDollyGizmos(CinemachineTrackedDolly target, GizmoType selectionType) { if (target.IsValid) { CinemachinePath path = target.m_Path as CinemachinePath; if (path != null) { CinemachinePathEditor.DrawPathGizmos(path, selectionType); } } }
private static void CreateDollyCameraWithPath() { CinemachineVirtualCamera vcam = CreateVirtualCamera( "CM vcam", typeof(CinemachineComposer), typeof(CinemachineTrackedDolly)); GameObject go = new GameObject( GenerateUniqueObjectName(typeof(CinemachinePath), "DollyTrack")); Undo.RegisterCreatedObjectUndo(go, "create track"); CinemachinePath path = Undo.AddComponent <CinemachinePath>(go); vcam.GetCinemachineComponent <CinemachineTrackedDolly>().m_Path = path; }
private static void CreateDollyTrackWithCart() { GameObject go = new GameObject( GenerateUniqueObjectName(typeof(CinemachinePath), "DollyTrack")); Undo.RegisterCreatedObjectUndo(go, "create track"); CinemachinePath path = Undo.AddComponent <CinemachinePath>(go); go = new GameObject(GenerateUniqueObjectName(typeof(CinemachineDollyCart), "DollyCart")); Undo.RegisterCreatedObjectUndo(go, "create cart"); CinemachineDollyCart cart = Undo.AddComponent <CinemachineDollyCart>(go); Undo.RecordObject(cart, "create track"); cart.m_Path = path; }
public void CreatePath() { if (cinemachinePath == null) { cinemachinePath = this.GetComponent <CinemachinePath>(); } if (offset.Equals(0) && round.Equals(0)) { CreatePathLinear(); } else { CreatePathRounded(); } }
void AddWaypoint(Transform child, int idx) { if (!child.GetComponent <CinemachinePath>()) { return; } CinemachinePath childCinemachinePath = child.GetComponent <CinemachinePath>(); CinemachinePath.Waypoint wp = childCinemachinePath.m_Waypoints[idx]; CinemachinePath.Waypoint targetWP = new CinemachinePath.Waypoint(); targetWP.position = child.localRotation * wp.position + child.localPosition; targetWP.tangent = child.localRotation * wp.tangent; targetWP.roll = wp.roll; generatedWaypoints[currentWaypointIndex] = targetWP; currentWaypointIndex++; }
IEnumerator MoveAlongPath(CinemachinePath path) { float duration = pathMovementCurve.Duration(); float progress = 0; Debug.Log("Starting lerp with a duration of " + duration); pathFollower.path = path; while (progress < 1) { progress += Time.deltaTime / duration; Debug.Log("progress is now " + progress); pathFollower.SetNormalizedPathPos(pathMovementCurve.Evaluate(progress * duration)); yield return(null); } ActivateGlyph(); }
public Lane PutCarOnLane(Lane target) { // Set lane and place car on GameObject _currentLane = target; if (CurrentRoad != _currentLane.Road) { CurrentRoad = _currentLane.Road; CheckForOffturn(); } // Set path CinemachinePath path = CurrentRoad.Path; _pathLength = path.PathLength; _cart.m_Path = path; // Set cart speed, position, and direction MovingForward = _currentLane.PositiveDirection; _cartSpeed = Speed * (MovingForward ? 1 : -1); _cart.m_Speed = _cartSpeed; _cart.m_Position = MovingForward ? 0 : _pathLength; return(_currentLane); }
internal static void DrawPathGizmos(CinemachinePath path, GizmoType selectionType) { // Draw the path Color colorOld = Gizmos.color; Gizmos.color = (Selection.activeGameObject == path.gameObject) ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor; float step = 1f / path.m_Resolution; Vector3 lastPos = path.EvaluatePosition(path.MinPos); Vector3 lastW = (path.EvaluateOrientation(path.MinPos) * Vector3.right) * path.m_Appearance.width / 2; for (float t = path.MinPos + step; t <= path.MaxPos + step / 2; t += step) { Vector3 p = path.EvaluatePosition(t); Quaternion q = path.EvaluateOrientation(t); Vector3 w = (q * Vector3.right) * path.m_Appearance.width / 2; Vector3 w2 = w * 1.2f; Vector3 p0 = p - w2; Vector3 p1 = p + w2; Gizmos.DrawLine(p0, p1); Gizmos.DrawLine(lastPos - lastW, p - w); Gizmos.DrawLine(lastPos + lastW, p + w); #if false // Show the normals, for debugging Gizmos.color = Color.red; Vector3 y = (q * Vector3.up) * path.m_Appearance.width / 2; Gizmos.DrawLine(p, p + y); Gizmos.color = (Selection.activeGameObject == path.gameObject) ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor; #endif lastPos = p; lastW = w; } Gizmos.color = colorOld; }
public void Copy() { if (path == null) { path = GetComponent <CinemachinePath>(); } if (path == null) { return; } if (singleMode) { path.m_Waypoints[target] = path.m_Waypoints[source]; } else { int diff = targetStart - sourceStart; for (int i = targetStart; i <= targetEnd; i++) { path.m_Waypoints[i] = path.m_Waypoints[i - diff]; } } }
private void Awake() { characterPath = GetComponent <CinemachinePath>(); }
private void Start() { path = GetComponent <CinemachinePath>(); }
static void DrawGizmos(CinemachinePath path, GizmoType selectionType) { DrawPathGizmo(path, (Selection.activeGameObject == path.gameObject) ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor); }
private void Awake() { _waitForSecondsResetPlayer = new WaitForSeconds(1); _cinemachinePath = (CinemachinePath)_cinemachineDollyCart.m_Path; }