Search Unity

How can i flip a plane mesh?

Discussion in 'General Graphics' started by Pitohui13, May 5, 2021.

  1. Pitohui13

    Pitohui13

    Joined:
    Dec 26, 2019
    Posts:
    14
    I have a plane mesh that needs to be flipped at the start of the program so it faces the right direction.

    I have written this code:
    Code (CSharp):
    1. public class Flip : MonoBehaviour
    2. {
    3.     public Plane p;
    4.     void Start()
    5.     {
    6.         p.Flip();
    7.     }
    8. }
    Is this the right way to do this,and if it is,how do i access the plane in question?(the Plane p does not show up in the inspector window)?
     
    nasos_333 likes this.
  2. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,349
    why not flip the holding gameobject of the mesh ?

    EDIT: if the mesh is procedural and not appear anywhere, then you have to do a 3D rotation to the mesh vertices i suppose. Or maybe just flipping the normals could work.
     
    Pitohui13 likes this.
  3. Pitohui13

    Pitohui13

    Joined:
    Dec 26, 2019
    Posts:
    14
    how do i flip a gameobject?Is that a seperate function?GameObject.Flip() does not exist.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    The
    Plane
    struct isn't the mesh. It's not even something that can be rendered. It's a
    Vector4
    value that's a normal and offset from the coordinate space center for an analytical plane. I.E.: It's for doing math stuff.

    If you're using the plane mesh created via GameObject > 3D Object > Plane, that's a Game Object with a Mesh Renderer component that's using the built in Mesh asset named Plane. Same name, but totally unrelated. If you want to "flip" that mesh, what you actually want to do is rotate the X or Z by 180 degrees, or invert the Y scale the game object's transform.

    Code (csharp):
    1. public class Flip : MonoBehaviour
    2. {
    3.     public Transform target;
    4.     void Start()
    5.     {
    6.         target.scale = target.scale * new Vector3(1f, -1f, 1f);
    7.     }
    8. }
    You could of course also just manipulate the game object in the editor before hand rather than using a script.
     
    BrandyStarbrite and Pitohui13 like this.
  5. Pitohui13

    Pitohui13

    Joined:
    Dec 26, 2019
    Posts:
    14
    Thanks so much!A very simple solution for a problem that i overengineered for multiple hours before asking this question ;)