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. Dismiss Notice

Creating a new Plane doesn't seem to set normal

Discussion in 'Scripting' started by frieldhelm446, Apr 14, 2021.

  1. frieldhelm446

    frieldhelm446

    Joined:
    Sep 27, 2020
    Posts:
    28
    When I create a Plane using
    Plane plane = new Plane(vector, position)
    , where vector is some nonzero unit vector and then check the Plane's normal vector using
    plane.vector
    , it returns (0,0,0). Is this a bug in Unity or am I doing something wrong?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Well there is no
    Plane.vector
    so that part is wrong at least.

    This is also working for me:
    Code (CSharp):
    1. print(new Plane(Vector3.up, Vector3.zero).normal);
    So I'd double check that you're not simply passing in a zero vector by accident or a bug in your code.
     
    Bunny83 and frieldhelm446 like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Works fine for me. My test code:

    Code (csharp):
    1.  
    2.         Plane plane = new Plane(Vector3.up, Random.onUnitSphere);
    3.  
    4.         Debug.Log(plane.normal);
    5.  
    What do you get if you print
    vector
    out BEFORE calling Plane?

    I'm betting that is (0,0,0) ... :)
     
    frieldhelm446 likes this.
  4. frieldhelm446

    frieldhelm446

    Joined:
    Sep 27, 2020
    Posts:
    28
    Sorry, I meant
    plane.normal
    .

    So If I print out the
    normal
    vector, it shows it is some nonzero vector, however after setting the normal of the plane,
    plane.normal
    , returns (0,0,0)
     
  5. frieldhelm446

    frieldhelm446

    Joined:
    Sep 27, 2020
    Posts:
    28
    Ah nvm, found the problem. I was initializing the wrong plane :(
     
    Kurt-Dekker likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    I have never done that... ever, at least in the past 27 minutes.
     
    frieldhelm446 likes this.
  7. elliot_eserin

    elliot_eserin

    Joined:
    Jan 5, 2020
    Posts:
    38
    Also... Make sure if you are setting it with 3 points that they don't all fall on the same line. Took me a while to notice that one...