Search Unity

Circle movement clockwise and counter clockwise

Discussion in '2D' started by DJVDJV, Aug 27, 2018.

  1. DJVDJV

    DJVDJV

    Joined:
    Sep 11, 2014
    Posts:
    70
    Hi. I got my object to move circle movement clockwise nicely with code:

    Code (CSharp):
    1. private float RotateSpeed = 1f;
    2. private float Radius =4f;
    3.  
    4. private Vector2 _centre;
    5. private float _angle;
    6.  
    7. private void Start()
    8. {
    9. _centre = transform.position;
    10. }
    11.  
    12. private void Update()
    13. {
    14.  
    15. _angle += RotateSpeed * Time.deltaTime;
    16.  
    17. var offset = new Vector2(Mathf.Sin(_angle), Mathf.Cos(_angle)) * Radius;
    18. transform.position = _centre + offset;
    19. }
    But now I have problems to change it to move counter clockwise..What I should change?
     
  2. barskey

    barskey

    Joined:
    Nov 19, 2017
    Posts:
    207
    Try
    _angle -= RotateSpeed * Time.deltaTime;
     
    DJVDJV likes this.