Search Unity

Sprite rotating around a point at constant distance.

Discussion in '2D' started by Balours, Dec 5, 2013.

  1. Balours

    Balours

    Joined:
    Nov 27, 2013
    Posts:
    59
    Hey all,
    I'm trying to make a sprite rotate around another one (or a point) at a constant distance.
    I tried to lookat the point then apply translate on the rotating object. But the movement is weird :

    $650px-Archimedean_spiral.svg.png

    Here's my code :

    Code (csharp):
    1.  
    2. Vector3 v3 = targetTransform.position - transform.position;
    3. float angle = Mathf.Atan2(v3.y, v3.x) * Mathf.Rad2Deg;
    4.  
    5. //The translate :
    6. transform.Translate (Vector3.up * movementSpeed * Time.deltaTime);
    7.  
    8. //The lookat :
    9. qTo = Quaternion.AngleAxis (angle, Vector3.forward);
    10. transform.rotation = qTo;
    11.  
    12.  
    Where am I wrong ?

    Thanks !
     
  2. Balours

    Balours

    Joined:
    Nov 27, 2013
    Posts:
    59
    Is this the wrong forum ?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What about Transform.RotateAround? (Probably Scripting would have been a better category since this isn't specifically about the 2D features.)

    --Eric
     
  4. Balours

    Balours

    Joined:
    Nov 27, 2013
    Posts:
    59
    Thank you Eric,
    It was easy with rotateAround ... rtfm balou, rtfm.