Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Check how hard a button was pressed

Discussion in '2D' started by Xanco78, Mar 8, 2015.

  1. Xanco78

    Xanco78

    Joined:
    Mar 8, 2015
    Posts:
    2
    Hi! First sorry for my english. I'm making a 2D platform game, and I'd like to know how to make my player jump higher if I press the button harder. I'm using axis. Here is my code, it's not the best, but it works. Thanks :)
    Code (CSharp):
    1. //Checks if the player is standing
    2.         if(isStanding  == true){
    3.         //Get the axis
    4.         jump = Input.GetAxis ("Jump");
    5.              //Add it to the player current velocity
    6.             r.velocity  = new Vector2(r.velocity.x, jumpHeight *jump);
    7.         }
     
  2. Miyavi

    Miyavi

    Joined:
    Mar 10, 2012
    Posts:
    58
    Hello,

    You can't check "how hard" a button is pressed, as these are digital. However, you can check how long you've been pressing them and act differently on each case.

    Check this if you're targeting PC or this if you're targeting mobile.
     
  3. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    897
    Actually some of the buttons on Sony's Dual Shocks are pressure sensitive. Dunno if/how they are supported in Unity.
     
  4. Xanco78

    Xanco78

    Joined:
    Mar 8, 2015
    Posts:
    2
    Ok, I'll try that, thanks!
     
  5. g r i l l a f a c e

    g r i l l a f a c e

    Joined:
    Jul 11, 2014
    Posts:
    2
    iOS MFI controller buttons are pressure sensitive as well. I believe I read in a recent update that unity now supports this: get axis should return a float between 0 and 1.