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

Input settings

Discussion in 'Editor & General Support' started by islanddreamer, Jun 28, 2006.

  1. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Is it possible to save and load input settings so that you don't have to reconfigure them manually every time you create a new project?
     
  2. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Good question! It takes a while to delete or re-do the defaults you don't need. I was wondering the same thing.
     
  3. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Yup...I am in the process of mapping 19 different inputs and I only want to have to do it once!
     
  4. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Some other questions re: inputs...

    Is there a way to set a sequence of keystrokes to trigger an animation?

    For example, in the game Psychonauts, pressing the LMB punches. Clicking twice in succession punches left then right. Clicking rapidly three times produces a combo.

    In another example, pressing the spacebar twice gives you a special jump. Punching while jumping is a "Palm Bomb" attack.
     
  5. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    You could do that I'm sure. One way I can think of:

    * Each keypress adds a value (the name of the function that was hit) to an array, coupled with the time it was hit.

    * Each hit also checks past hits in the array to see if there's a combo to trigger, by comparing the times.

    * If you only want to have to check ONE previous hit (might not even need an array then), what you would do it when you DO detect a combo (say a double-hit) you store THAT name as the latest function ("double punch," say). Then the third hit can look at that and compare the time and know if a triple-hit is triggered or not.

    (It's easier if you don't have to compare times--like a cheat code where you enter the sequence as slowly as you like.)
     
  6. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Thanks for explaining the theory. But what I need is a code snippet or direction to the inputs that will allow me to set this behavior. I'm only a kindergartener when it comes to coding!
     
  7. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    I've had luck simply copying the Input Manager file in the Library of your project to another project. I take no responsibility for the results of this, though, so back up. :)

    -Jon
     
  8. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    OK, let's see... here's my attempt at detecting double and triple combo moves, plus an example combo involving two different keys (the LugiePunch).

    This is UNtested, and it's from a Unity and JavaScript newbie (as of 2 weeks ago). I hope I have the "switch" syntax right but I've never used it--it's new in 1.5. So the odds of it working without some tweaking are slim, but here goes...

    Code (csharp):
    1.  
    2. private var lastkeydown = "None";
    3. private var lastkeytime = 0.0;
    4. private var keydelay = .2; //Maximum allowed delay between combo presses
    5.  
    6. function Update()
    7. {
    8.     if (Input.GetButtonDown("Punch"))
    9.     {
    10.         //Punch key was hit, now need to determine whether it's a combo:
    11.         if ( (Time.time - lastkeytime) < keydelay ) //Key was hit fast enough, so combo is possible
    12.         {
    13.             switch (lastkeydown) //Check lastkeydown action, then change it to THIS action
    14.             {
    15.             case "Punch":
    16.                 lastkeydown = "DoublePunch"; //Punched before, so this is a double
    17.             break;
    18.             case "DoublePunch": //Double before, so this is a triple
    19.                 lastkeydown = "TriplePunch";
    20.             break;
    21.             case "SpitBigLugie": //Another key before, that makes a combo when followed by a Punch, so this is now a two-key combo
    22.                 lastkeydown = "LugiePunch";
    23.             break;
    24.             default:
    25.                 lastkeydown = "Punch"; //Previous key was irrelevant to Punch, so no combo, this is just a plain Punch
    26.             }
    27.         }
    28.         else //Pressed too late, no combo, just a plain Punch
    29.         {
    30.             lastkeydown = "Punch";
    31.         }
    32.  
    33.         //Now that we know whether it's a combo or not and have updated lastkeydown to the correct action, execute the result:
    34.         switch (lastkeydown)
    35.         {
    36.         case "Punch":
    37.             //Resulting actions for Punch
    38.         case "DoublePunch":
    39.             //Resulting actions for DoublePunch
    40.         case "TriplePunch":
    41.             //Resulting actions for TriplePunch
    42.         case "LugiePunch":
    43.             //Resulting actions for LugiePunch
    44.         }
    45.     }
    46.    
    47.     //Implement more keys and more combos as needed:
    48.     if (Input.GetButtonDown("SpitBigLugie"))
    49.     {
    50.         //Variations on the above to detect combos ending in SpitBigLugie
    51.         //(the key that ENDS the combo triggers the action)
    52.     }
    53. }
    54.  
    Let me know what I screwed up :)
     
  9. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Ok, trying to adapt your script to my available loops...

    Are Punch, DoublePunch, TriplePunch etc. supposed to be animation loop names? Can I declare
    Code (csharp):
    1. animation["Punch"], etc.
    at the top of this script?
    Or do I enter the loops names after
    Code (csharp):
    1. {
    2. case "Punch":
    3. ...
     
  10. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    "Punch" and "SpitBigLugie" would be names of inputs (keys/buttons) you have defined.

    "DoublePunch," "TriplePunch," and "LugiePunch" are just names of actions that are stored to be acted upon later down the script. They mean nothing until you get to the "resulting actions" further down.

    So whatever you want to HAPPEN you would have to enter where it says:
    //Resulting actions for Punch

    Now, if using the action name as an animation clip name helps you achieve your goal, then that sounds like a good method. But in my example, the action names are nothing more than a way to store what action has been chosen, and then act on it.

    As far as HOW you would connect the actions to an animation loop, I've never used animation loops so I don't know the best way I'm afraid :)
     
  11. islanddreamer

    islanddreamer

    Joined:
    Apr 29, 2006
    Posts:
    473
    Got it, thanks.

    If you're interested in testing Unity with some animation loops, go to the Alias community site (you can register for free as a Bronze member) and then you can find some great FBX loops you can play with. Let me know if you need a direct link.
     
  12. delirious

    delirious

    Joined:
    Jun 19, 2007
    Posts:
    3
    Morgan--
    Haven't tried this yet, but reading through it, it is very clear to me now! Thanx for the well documented switch code example. This should be in the script tutorials!


    IslandDreamer--
    please post the direct link...
     
  13. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Hope it works :) It was so long ago I don't even remember it :)
     
  14. Overnaut

    Overnaut

    Joined:
    Aug 25, 2017
    Posts:
    19
    In Unity 2017.3 the location of the input manager configuration is
    Code (CSharp):
    1. yourProjectName/ProjectSettings/InputManager.asset