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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[SOLVED]getting a normalized forward vector("best" way)?

Discussion in 'Scripting' started by wtfiswiththisnamething, Jul 7, 2015.

  1. wtfiswiththisnamething

    wtfiswiththisnamething

    Joined:
    Jul 7, 2015
    Posts:
    5
    Hey Guys,

    I need a vector that is normalized and always points into the "front" direction of my object.

    I tried "transform.forward = FrontVector;" but that doesnt work at all.

    because i needet a fast solution i wrote :
    1.PNG
    and then i made the direction vector : 2.PNG

    and i think this is a bit unfavorable.

    the second try was to make a child obj, and then calculate the vector (Parent-Child).

    both works, but i dunno if there is a better solution, or if one of these is the best.

    sfmbe
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    OP, I think you have your assignment backwards...

    Code (csharp):
    1.  
    2. transform.forward = FrontVector;
    3.  
    This will rotate the gameobject to face in the direction of FrontVector.

    You probably want:

    Code (csharp):
    1.  
    2. FrontVector = transform.forward;
    3.  
    That gets the value of forward, and sets FrontVector to it.
     
  4. wtfiswiththisnamething

    wtfiswiththisnamething

    Joined:
    Jul 7, 2015
    Posts:
    5
    ooooops sry i cant belive i did that :eek:.

    ty for your help, now it works <3