public Quaternion GetEndRotation() { //return Quaternion.AngleAxis(180, otherEndFibreOpticController.transform.up) * otherEndFibreOpticController.transform.rotation; return(GlobalGravityControl.GetRotationToDir(otherEndFibreOpticController.GetDirection())); }
/* * Handles transition logic for fibreoptic warps. * * Transitions to the start of the fibre, then along it */ IEnumerator FibreTransitionCamera() { float fibreOpticDuration = fibreOpticController.GetDuration(); float totalDuration = duration + fibreOpticDuration; bool transitionFov = totalDuration > 0.5f; float t = 0.0f; while (t < 1.0f) { t += Time.deltaTime * (Time.timeScale / duration); t = Mathf.Clamp01(t); float lerpPercent = t * t * t; // modify t value to allow non-linear transitions // lerp position and rotation transform.position = Vector3.Lerp(startPos, fibreOpticController.GetPosition(), lerpPercent); transform.rotation = Quaternion.Lerp(startRot, fibreOpticController.GetStartRotation(), lerpPercent); // Warp camera effects float totalT = (t * duration) / totalDuration; WarpCameraEffects(totalT, transitionFov); yield return(0); } // Fibre optic warp transition here float t2 = 0f; while (t2 < 1f) { t2 += Time.deltaTime * (Time.timeScale / fibreOpticDuration); t2 = Mathf.Clamp01(t2); transform.position = fibreOpticController.GetBezierPosition(t2); Vector3 tangent = fibreOpticController.GetBezierTangent(t2); Quaternion newRotation = GlobalGravityControl.GetRotationToDir(tangent); // rotate camera to face bezier tangent and lean slightly depending on angle of turn // Lots of calculations. may be a bit much for such a subtle effect :P float tAlt = Mathf.Abs((2f * t2) - 1f); tAlt = 1f - (tAlt * tAlt); Vector3 flattened = Vector3.ProjectOnPlane(tangent, transform.up).normalized; float angle = Vector3.Angle(transform.forward, flattened) * 10f * tAlt; float dot = Vector3.Dot(tangent, transform.right); Quaternion lean = Quaternion.AngleAxis((dot < 0) ? angle : -angle, tangent); newRotation = Quaternion.RotateTowards(newRotation, lean * newRotation, 10f); transform.rotation = newRotation; // Warp camera effects float totalT = (duration + (t2 * fibreOpticDuration)) / totalDuration; WarpCameraEffects(totalT, transitionFov); yield return(0); } Info <Vector3, Vector3, bool, FibreOpticController> info = new Info <Vector3, Vector3, bool, FibreOpticController>(knifeController.GetWarpPosition(), knifeController.transform.up, knifeController.AutoWarp(), fibreOpticController); this.PostNotification(WarpEndNotification, info); //Destroy(gameObject); Disable(); }
// Get rotations for aligning transition camera public Quaternion GetStartRotation() { return(GlobalGravityControl.GetRotationToDir(-GetDirection())); }