Search Unity

Rotate Around and Look At Problem

Discussion in 'Scripting' started by yesimarobot, May 14, 2010.

  1. yesimarobot

    yesimarobot

    Joined:
    Jun 19, 2009
    Posts:
    24
    I'm using the following code to get prototype for moving an object around a spherical object and keeping the object perpendicular to the sphere.

    Code (csharp):
    1.  
    2. var speed = 100.0;
    3. var planet : Transform;
    4.  
    5. function Update () {
    6.     var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed *-1;
    7.     transform.RotateAround(Vector3(0, -512, 0), Vector3.forward, x);
    8.     transform.LookAt(planet);
    9. }
    10.  
    The result is sort of working. I see the following behavior when the object orbiting crosses the halfway point of the sphere. It rotates 180 on the z axis.