I have two triangle game objects T1 and T2 that I am trying to orbit T2 around T1 without changing the direction that it faces. I have the following code
t2.transform.RotateAround (t1.transform.position, Vector3.forward, 90);
When I use the following code it points t2 in another direction. I want to keep the direction while orbiting t1. Any help please?
The simplest solution is to just save and restore the rotation around the RotateAround() call:
var q : Quaernion = t2.tansform.rotation;
t2.transform.RotateAround (t1.transform.position, Vector3.forward, 90);
t2.transform.rotation = q;
Another solution I often post is to rotate a vector and use that to position your object. To start you would place t2 in the correct orbit and facing the correct direction in the inspector. Then the top of your script you would do:
#pragma strict
public var v : Vector3;
function Start() {
v = t2.transform.position - t1.transform.position;
}
Then to rotate, you would do:
v = Quaternion.AngleAxis(90.0, Vector3.forward) * v;
v2.transform.position = v1.transform.position + v;