- Home /
Rotating around another object?
Hey! I have been trying to make one object rotate around another (like the moon orbiting the earth). What I want it to do is just to simply rotate the player; however, when I use the iTween Visual rotateBy method, the object just rotates on it's axis. I have tried making the cube a child of the player, and vice versa. I am more comfortable with javascript. Any ideas?
Have you tried using the Transform.RotateAround code? You can use that to have an object rotate around any other point in space (which you could get using the location fo the other object).
In a new scene, create a cube, position it at (5,0,0), attach this script :
var PlanetRotateSpeed : float = -25.0;
var OrbitSpeed : float = 7.0;
function Update() {
// planet to spin on it's own axis
transform.Rotate(transform.up * PlanetRotateSpeed * Time.deltaTime);
// planet to travel along a path that rotates around the sun
transform.RotateAround (Vector3.zero, Vector3.up, OrbitSpeed * Time.deltaTime);
}
http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html
http://docs.unity3d.com/Documentation/ScriptReference/Transform.RotateAround.html
I looked at it but could not get it to work.... I'm not very good with Vector3, but I'll try!
not exactly what I need... I need an object to rotate the player. For a little more info, this is for random teleportation. I was going to have this object orbiting the player and then slowly decreasing the range that it can teleport to.
Your answer
Follow this Question
Related Questions
Having problem with itween.moveto and oreinttopath 0 Answers
iTween acting strangely when being used to move camera 0 Answers
Unity hangs when trying to load an image from url using the WWW class 1 Answer
iTween : moving along path, within a rotating reference frame 0 Answers
Spinning rigidbody platform in 2D 0 Answers