Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Is not greater than? (UNSOLVED)

Discussion in 'Scripting' started by LightWell, Sep 23, 2014.

  1. LightWell

    LightWell

    Joined:
    Sep 6, 2014
    Posts:
    43
    So, I am adding a lean feature into my character controller right, and so, I was making sure that you aren't leaning too far right or left, so:
    Code (JavaScript):
    1. if( sidespeed > 0 && transform.rotation.x !< 15 || !transform.rotation.x !> -15) {
    2. cam.transform.Rotate(lean, 0, 0);
    3. }
    So, this probably is all messed up as is, and really I was just doing it too learn how, but anyways, guys, how would I make an if statement check for: is not greater than and is not less than, thanks!
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    "Not greater than" is the same thing as "less than or equals".

    I changed the last || to &&, and I'm guessing you probably wanted to add some parenthesis since in your case if the last thing, the !transform.rotations !> -15 is true, then the whole if statement is true. You can see the rules about order of operations here.
    http://msdn.microsoft.com/en-us/library/aa691323(v=vs.71).aspx

    Also, a rotation's/quaternion's x component is *not* the same thing as it's x euler angle. If you want the same value that you see in the Transform's inspector, then you need to use transform.rotation.eulerAngles.x instead.
    Code (csharp):
    1. if (sidespeed > 0 && (transform.rotation.eulerAngles.x <= 15 && transform.rotation.eulerAngles.x >= -15))
    This might be easier written using an Angle function.
    Code (csharp):
    1. if (sidespeed > 0 && Vector3.Angle(transform.up, Vector3.up) <= 15)
     
    Last edited: Sep 23, 2014
    angrypenguin likes this.