Search Unity

How do you change the direction (not magnitude) of a Vector2?

Discussion in 'Physics' started by TheHammer1, May 22, 2019.

  1. TheHammer1

    TheHammer1

    Joined:
    Oct 15, 2015
    Posts:
    25
    I want to:
    - get a vector
    - change the direction of it
    - not change the magnitude.

    I've tried to change the direction by applying an offset to the vector2, but this has proven unsuccessful.

    My end product should return a normalized vector, so that I can apply speed to it.
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    But if you normalize a vector, then you do change its magnitude.

    If you want to rotate the vector to a new direction, you might want to use Quarternion.Euler().
     
    SparrowGS likes this.
  3. RidentRaptor

    RidentRaptor

    Joined:
    Apr 11, 2019
    Posts:
    6
    As PGJ said, if you normalize the vector before actually using it, then its magnitude shouldn't matter.

    If you still need that functionality, you can get the magnitude of the vector before changing it, then once you do change it, normalize it and multiply it by the stored magnitude.
     
    Last edited: Jun 16, 2019
    SparrowGS likes this.