Created
July 13, 2016 05:57
-
-
Save kennir/1b545c55e2ab40d36ce536a1711d032d to your computer and use it in GitHub Desktop.
RotateAround in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Update () { | |
//this.transform.RotateAround(this.transform.parent.position, this.transform.parent.up, 1); | |
MyRotateAround(this.transform.parent.position, this.transform.parent.up, 1); | |
} | |
void MyRotateAround(Vector3 pos, Vector3 up, float degree) | |
{ | |
Quaternion q = Quaternion.AngleAxis(degree, up); | |
this.transform.position = q * (this.transform.position-pos) + pos; | |
this.transform.rotation *= q; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment