Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Coordinates after rotation

Discussion in 'Scripting' started by ToomToomToom, Jan 14, 2020.

  1. ToomToomToom

    ToomToomToom

    Joined:
    Jul 8, 2017
    Posts:
    6
    Hi,
    I need to recalculate given coordinates (A) to predict location of the object, after rotation (B).
    What is idea for doing that with C# - should I use some kind of loop for that?
    upload_2020-1-14_7-40-58.png

    Thank you in advance for the answer.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,594
    You need trigonometry, to calculate x and y based on angle.
    For 2D Cartesian space, you need use cosine for x and sine for y position.
    Look into trigonometry equations.
    You also need position offset.
     
  3. ToomToomToom

    ToomToomToom

    Joined:
    Jul 8, 2017
    Posts:
    6

    Thanks. Could you please give me some example how to do this with c#?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,594
    In fact, if you just rotate 90 degrees, then you just flip axis coordinates, with relevant offset.
    So no need for any trigonometry really.
     
    ToomToomToom likes this.