Skip to content

Instantly share code, notes, and snippets.

@tarob19
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarob19/81bec64893ecde2fe454 to your computer and use it in GitHub Desktop.
Save tarob19/81bec64893ecde2fe454 to your computer and use it in GitHub Desktop.
Rotate sample component
using UnityEngine;
using System.Collections;
public class RotateTest : MonoBehaviour
{
public GameObject target;
public Vector3 additional;
Quaternion _rot;
Quaternion _initRot;
Vector3 _vec;
// Use this for initialization
void Start ()
{
_initRot = transform.rotation;
_rot = Quaternion.identity;
_vec = transform.position - target.transform.position;
}
// Update is called once per frame
void Update ()
{
_rot *= Quaternion.AngleAxis (180f * Time.deltaTime, Vector3.up);
var r = _rot * Quaternion.Euler (additional);
transform.position = r * _vec + target.transform.position;
transform.rotation = r * _initRot;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment