Skip to content

Instantly share code, notes, and snippets.

@Chillu1
Created May 10, 2021 08:45
Show Gist options
  • Save Chillu1/001a5341b3c24e2dc0634ecb480223fe to your computer and use it in GitHub Desktop.
Save Chillu1/001a5341b3c24e2dc0634ecb480223fe to your computer and use it in GitHub Desktop.
SimpleTrailerCamera
using System.Collections;
using System.Linq;
using DG.Tweening;
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class TrailerCamera : MonoBehaviour
{
public void StartCameraMovementCommand()
{
StartCoroutine(StartCameraMovement());
}
private IEnumerator StartCameraMovement()
{
yield return new WaitForSeconds(1);//No stuttering
while (true)
{
var sequence = DOTween.Sequence();
float[] times = new[] {3.5f, 2.5f, 3f, 2.5f, 3f, 2.5f, 2f, 1.2f};
//UnityEditor.TransformWorldPlacementJSON:{"position":{"x":-25.660751342773439,"y":34.57048416137695,"z":130.88284301757813},
//"rotation":{"x":0.13222095370292664,"y":0.8680281639099121,"z":-0.35391363501548769,"w":0.3221643567085266},"scale":{"x":1.0,"y":1.0,"z":1.0}}
//transform.SetPositionAndRotation(new Vector3(29.48462677001953f,69.50728607177735f,43.163055419921878f), new Quaternion(0.5027862787246704f,0.49796760082244875f,-0.49973246455192568f,0.4995015859603882f));
sequence
.Append(transform.DOMove(new Vector3(-35.3f, 33.2f, 46.3f), times[0]))
.Join(transform.DORotateQuaternion(new Quaternion(-0.17556f, -0.6833f, 0.17352f, -0.68706f), times[0]))
.AppendInterval(times[0] * 0.03125f)
//Diag
.Append(transform.DOMove(new Vector3(-32.5424f, 33.94598f, -16.89196f), times[1]))
.Join(transform.DORotateQuaternion(new Quaternion(-0.20950f, -0.522492f, 0.1332752f, -0.815688f), times[1]))
.AppendInterval(times[1] * 0.03125f)
.Append(transform.DOMove(new Vector3(31.7470f, 34.058494f, -46.901954f), times[2]))
.Join(transform.DORotateQuaternion(new Quaternion(-0.2613526f, -0.008413f, 0.0014979f, -0.9652056f), times[2]))
.AppendInterval(times[2] * 0.03125f)
//Diag
.Append(transform.DOMove(new Vector3(87.004135f, 34.1455268f, -35.32309f), times[3]))
.Join(transform.DORotateQuaternion(new Quaternion(-0.342872f, 0.29041713476f, -0.113218091f, -0.88615912f), times[3]))
.AppendInterval(times[3] * 0.03125f)
.Append(transform.DOMove(new Vector3(92.81848f, 34.2702407f, 46.82397842f), times[4]))
.Join(transform.DORotateQuaternion(new Quaternion(-0.2523360f, 0.6590921f, -0.25236f, -0.6619927f), times[4]))
.AppendInterval(times[4] * 0.03125f)
//Diag
.Append(transform.DOMove(new Vector3(88.0455f, 34.3991546f, 131.870010f), times[5]))
.Join(transform.DORotateQuaternion(new Quaternion(-0.1574f, 0.837423f, -0.320282f, -0.413955f), times[5]))
.AppendInterval(times[5] * 0.03125f)
.Append(transform.DOMove(new Vector3(30.8453f, 34.48529f, 131.98231f), times[6]))
.Join(transform.DORotateQuaternion(new Quaternion(0.001916f, 0.924171f, -0.3819f, 0.00266f), times[6]))
.AppendInterval(times[6] * 0.03125f)
//Diag
.Append(transform.DOMove(new Vector3(-25.6607f, 34.57048f, 130.88284f), times[7]))
.Join(transform.DORotateQuaternion(new Quaternion(0.132220f, 0.86802f, -0.35391f, 0.322164f), times[7]))
.AppendInterval(times[7] * 0.03125f);
sequence.SetRecyclable();
sequence.Play();
yield return new WaitForSeconds(times.Sum() + times.Sum()*0.03125f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment