- Home /
rotateAround not working correctly
I'm trying to rotate one sphere around another sphere, like a planet around a sun. No matter what I do tho, the planet object only rotates around it's axis and doesn't move. This is the code I'm using:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Update() {
transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
}
I've tried to set the first Vector3 to the transform.position of my Sun object, but no matter what I do, it just sits in one place and rotates on its own axis but never actually moves. Doesn't matter what I put in there, it seems.
What am I doing wrong?
Answer by JamesLeeNZ · Jun 19, 2013 at 11:53 PM
Make sure you have offset your planet.
The code you have written will rotate around world.zero, but if your planet is sitting at world zero, there is no rotation distance.
The first parameter must be the sun position, and the planet must be at a different position, as @JamesLeeNZ said: with this arrangement, the planet will orbit the sun in the Y axis.
Your answer
Follow this Question
Related Questions
Rolling Cube with Rigidbody? 5 Answers
Enemy circeling around Player 0 Answers
defining a relative axis of rotation 1 Answer
How do I rotate on a new pivot point with RotateAround? 2 Answers
RotateAround a player 1 Answer