Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Input

Discussion in 'Scripting' started by AaronC, Dec 23, 2006.

  1. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,553
    Hi
    Im trying to get my 3rd person character to play its walk cycle on more keys than forwards(namely backwards and sideways as well)

    He has a rigidbodyfps controller on him to move him in 3d space, and a mouselook to turn him and ideally Id like a "GetKeyDown("AnyKey")" type thing to work. Heres my current working script
    Code (csharp):
    1. private var waswPressed = false;
    2. function Update()
    3. {
    4. if (Input.GetKey("w")) {
    5.  waswPressed = true;
    6.   print("animating");
    7.   animation.Stop("Idle");
    8.   animation.Play("Walk");
    9.   }
    10.   else
    11.  {  waswPressed = false;
    12.  print("HanginOut");
    13.  animation.Play("Idle");
    14.  animation.Stop("Walk");
    15. }
    16. }
    I cannot find anything in the docs or examples to go further on this. I need to use a rigidbody fps controller in order to detect a collision, so I dont really want to use a character controller. Ive looked at the "GetAxis" approach, and it look like you can use horizontal, or vertical, but not both. Its either a walk or idle animation, so getanykey would be great but It never compliles without errors... Any leads anyone? Thanks
    AC
     
  2. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    try this as your if line:

    if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
     
  3. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,553
    Thanks heaps Yoggy! that worked a charm-how did you learn all this stuff?
    things like the != 0 || part of your statement and bits like "" and "=="
    intrigue me...
    thanks man, that fixes the last bug in my 3du entry-though its too late for the gig, it satisys me greatly to finish this...Happy Summer Solstice-though its probably winter solstice where you are...
    Aaron
     
  4. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Those are the logical operators in javascript.

    When reading them aloud replace "==" with "is equal to", "!=" with "is not equal to", "||" with "or" and "" becomes "and".

    So in English, "if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)" roughly translates to "If the Horizontal input axis is not equal to zero or the vertical input axis is not equal to zero."
     
  5. bronxbomber92

    bronxbomber92

    Joined:
    Nov 11, 2006
    Posts:
    888
    Does Javascript have bitwise operators? Like, << - left bit shift, >> - right bit shift, |, , and that "XOR"... Not sure how that one is represented...
     
  6. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,553
    Cool I was wondering how to express those things-Thanks Keli
    AC
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,777
    I know it has all of those (they are used to scriptify layer masks), except for XOR I'm not sure about - I think the operator for that is traditionally ^ but don't quote me on that.