var y : float = 5;
var speed : float = 10;
var angle : float ;
function Start () {
}
function Update ()
{
for(angle = 0 ; angle <= 90 ; angle = angle + 0.01)
{
transform.Translate( 5 , y * Mathf.Sin(angle) , 5* Mathf.Cos(angle));
}
}
iwas trying to rotate a ball around a point but the numbers of x,y,z go to enormous amounts … ok ,now there could be some mistake with the y ,z but why is the x changing??? … and could you guys get me solutuion to make my sphere revolve around origin in y-plane
Just in case you didn’t realised your for-loop does 9000 iterations
Mathf.Sin and Mathf.Cos don’t take an angle in degree but in radians. Unity has two factors to convert Deg2Rad or Rad2Deg.
All code inside Update is executed within a frame. So whatever you so it’s finished within a fraction of a second.
The Translate method takes offset values by which you want to translate the object. Since you pass 5 for x, each time you call the function you add 5 to the position in x-direction.
like @xandermacleod said if you want to just constantly rotate the object around another on a fix distance, it’s easier to parent the object to an empty GameObject, put the empty GO in the center of your circle and offset the actual object within the parent so it’s on your desired path. Now when you rotate the parent the child will follow a circular path around the center.