Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Aladine · May 03, 2014 at 11:46 PM · inputaxis

Input.GetKeyUp for Axis input

Hello everyone,

the situation is that i need the player to jump after the space key is released, so this works perfectly

 if (Input.GetKeyUp (KeyCode.Space)) {
       //do stuff
     }

but i need to use custom input instead, i tried doing this :

  if (Input.GetAxisRaw("P1Jump")==0) {
           //do stuff
         }

however the result was obviously the player jumping all the time, what i don't understand is why when i print GetKeyUp i always get false but it is only triggered when i actually press and release the key, but when the Axis Raw it is always zero and it's always calling doing something

thank you

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Jeff-Kesselman · May 04, 2014 at 12:46 AM

Make sure to set your axis type to "KeyOrMOuseButton"

Then read it using Input.GetButtonUp

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aladine · May 04, 2014 at 02:30 AM 0
Share

and i just add a positive button ?

avatar image Aladine · May 04, 2014 at 02:32 AM 0
Share

Perfect!! thank you :-)

avatar image
2

Answer by AlucardJay · May 04, 2014 at 12:50 AM

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButtonUp.html

It will not return true until the user has pressed the button and released it again.

This is just how it works. GetKey goes through a cycle of states :

  • Idle

  • pressed Down

  • Held down

  • released Up

So GetKeyUp is only true after being held down then released, not if it is idle.

You could emulate an axis behaving like a button like this :

 #pragma strict
 
 enum AxisState
 {
     Idle,
     Down,
     Held,
     Up
 }
 
 var axisState : AxisState;
 
 var deadZone : float = 0.02;
 
 
 function Update() 
 {
     switch ( axisState )
     {
         case AxisState.Idle :
             if ( Input.GetAxis( "Horizontal" ) < -deadZone || Input.GetAxis( "Horizontal" ) > deadZone )
             {
                 axisState = AxisState.Down;
             }
         break;
         
         case AxisState.Down :
             axisState = AxisState.Held;
         break;
         
         case AxisState.Held :
             if ( Input.GetAxis( "Horizontal" ) > -deadZone && Input.GetAxis( "Horizontal" ) < deadZone )
             {
                 axisState = AxisState.Up;
             }
         break;
         
         case AxisState.Up :
             axisState = AxisState.Idle;
         break;
     }
     
     Debug.Log( axisState );
 }

in your example, to check for an axis up state would be :

 if (axisState == AxisState.Up) {
     //do stuff
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Read analog stick input without using the Input Manager 1 Answer

Detect Gyroscope's rotation around a single axis? Like a car game. 0 Answers

C# HUD axis button display 0 Answers

Logitech G27 pedal input 1 Answer

Does unity support a 16 bits axis input? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges