private IEnumerator RotateAndMoveGameObject(GameObject gameObject, Vector3 OriginalPosition, Vector3 FinalPosition, float Speed, Vector3 OriginalRotation, Vector3 FinalRotation, float RotationSpeed, CutsceneLerps WhichLerp) { Vector3 rotationVector = Vector3.zero; for (float i = 0.0f; i <= 1.0f; i += Speed) { if (Vector3.Distance(gameObject.transform.position, FinalPosition) < 0.01f) { if (gameObject.transform.rotation == Quaternion.Euler(FinalRotation)) { break; } } SmoothLerp(gameObject.gameObject, OriginalPosition, FinalPosition, i, WhichLerp); rotationVector = Vector3.Lerp(OriginalRotation, FinalRotation, i * RotationSpeed); gameObject.transform.rotation = Quaternion.Euler(rotationVector); yield return(new WaitForSeconds(0.01f)); } IsRotateAndMoveCamera = false; yield return(null); }
public void SmoothLerp(GameObject gobject, Vector3 start, Vector3 goal, float alpha, CutsceneLerps WhichLerp) { if (WhichLerp == CutsceneLerps.slowfastslow) { gobject.transform.position = Vector3.Lerp(start, goal, 0.5f * Mathf.Sin(Mathf.PI * alpha - Mathf.PI / 2.0f) + 0.5f); } else if (WhichLerp == CutsceneLerps.fastslow) { gobject.transform.position = Vector3.Lerp(start, goal, Mathf.Sin(0.5f * Mathf.PI * alpha)); } else if (WhichLerp == CutsceneLerps.slowfast) { gobject.transform.position = Vector3.Lerp(start, goal, Mathf.Sin(0.5f * (Mathf.PI * alpha - Mathf.PI)) + 1.0f); } else if (WhichLerp == CutsceneLerps.fastslowfast) { gobject.transform.position = Vector3.Lerp(start, goal, (1.0f / Mathf.PI) * Mathf.Asin(2.0f * alpha - 1.0f) + 0.5f); } else if (WhichLerp == CutsceneLerps.normal) { gobject.transform.position = Vector3.Lerp(start, goal, alpha); } }