Search Unity

C# locking z position to 0

Discussion in 'Scripting' started by From-Soy-Sauce, Jul 24, 2014.

  1. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    Hi, I'm trying to make a Smash Bros like game, and I wanted to ask how I would go about making sure that the objects do not have a Z other then 0.
     
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Attach a Rigidbody and you can freeze the position and rotation on the Z
     
  3. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Or:

    Vector3 rotation = transform.localEulerAngles;
    Rotation.z = 0;
    transform.localEulerAngles = rotation.

    Do the same for position.
     
  4. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    I'm sorry, I've been trying to figure out how to do things for your first suggested method with no success. Would you please elaborate on it?

    Your second suggestion sounds interesting too, but I don't really understand what you mean by "do the same for position."

    edit--
    Nevermind I got it!
     
    Last edited: Jul 24, 2014
  5. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
  6. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    For the first, the image should show enough. That should prevent the object from moving on that axis.
     

    Attached Files: