- Home /
How to make an object follow the rotation of another object?
how to make an object following another object rotating around a circle?
Answer by Cherno · Jun 26, 2015 at 02:32 AM
So, object A stands still and rotates in a circular motion, right? Then you can just pass this object's transform.rotation to the transform.rotation of the object that should follow it. If you only want to use the y rotation, then take the y value of the first object's eulerAngles and pass it to the second object's eulerAngles.
Transform object_a;
Transform object_b;
float euler_y = object_a.eulerAngles.y;
object_b.eulerAngles = new Vector3(object_b.eulerAngles.x, euler_y, object_b.eulerAngles.z);
If the following object should rotate towards the edge of the circle, then you just take the first object's transform.positon and add it's forward direction vector times the radius.
Transform object_a;
Transform object_b;
float radius = 3f;
Vector3 circleEdgePos = object_a.position + object_a.forward * radius;
object_b.LookAt(circleEdgePos );
Answer by MarceloCosta_GamesBR · Jun 27, 2015 at 10:48 PM
i am using this for the object_b, because i need controll mecanim velocity
void OnAnimatorMove(){
newPos = anim.rootPosition;
newRot= anim.rootRotation;
transform.position = newPos;
transform.rotation= newRot;
}
Is this an actual solution to your question? Please post comments as comments and answers as answers.
Your answer
Follow this Question
Related Questions
Need help with rotation 4 Answers
Spawning objects to the surface of a spehere correctly. 0 Answers
Obtain angle from given rotation 1 Answer
make enemy only follow along the X and Z axis 1 Answer
Rotating wrong 0 Answers