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

Why vertical and horizontal axes have the same axis in input manager?

Discussion in 'Getting Started' started by AdrianHil, Feb 2, 2018.

  1. AdrianHil

    AdrianHil

    Joined:
    Feb 1, 2018
    Posts:
    26
    Hi,

    Im just starting with Unity and there is one thing that is bothering me - why the both: vertical and horizontal axes have set up the same axis like on the attachment below ? and whats bother me more - why is that working correctly ? Changing axis doesn't change anything in case of my simple code (look at attachment) - why is that ? like if buttons values were only things that matters..
    axes.JPG code.JPG

    Hope there is someone who could help me to understand it, i'll be grateful
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    AdrianHil and JoeStrout like this.
  3. AdrianHil

    AdrianHil

    Joined:
    Feb 1, 2018
    Posts:
    26
    Thanks for fast answer and the link! I read that before I submit that post but I assumed that "etc" in this sentence "Axis of input from the device (joystick, mouse, gamepad, etc.)" will also cover the keyboard :p But let's say that it true and axis is relevant only for mouse, joystic and gamepad then how unity knows which position (X or Z) should be changed when I'm clicking on specific buttons on keyboard ? Is it somehow hardcoded inside unity that clicking left/right arrows will affect X position and pressing up/bottom arrows will affect Z position ? :)
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Not really. For your code, let's say.. it gives a "positive" and "negative" value based on the keys (and/or secondary keys) that you supply into the Input Manager.
    It's usually you (the programmer) that decides how to use those values (to move, or what not).

    See how you told it to add force based on the value(s) ? You could have just the same asked it to change a colour or print a message based on the input value. :)

    Does that make sense?
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Right, when you say GetAxis("Vertical"), then it looks for a definition of that in Input Manager. It finds the second one in your screen shot, which defines the keys as "down" and "up" (with alternate keys "s" and "w"). So those are the keys mapped to the vertical axis.

    @methos5k is right, the "Axis" listed there refers to joystick/mouse axis, and only matters if you set the type to mouse movement or joystick axis.
     
    AdrianHil likes this.
  6. AdrianHil

    AdrianHil

    Joined:
    Feb 1, 2018
    Posts:
    26
    Sorry guys, I think that I asked my question in wrong way - I know that Unity look for an imput in imput manager when I call GetAxis("Vertical") but by my question I was meant how it happens that if we get axis "vertical" then program will know that he has to modify Z position of object when we press button connected with specific axes:
    upload_2018-2-2_23-25-39.png

    I was probably blinded by something when asking this question :) because it seems quite obvious for me now that method "AddForce" has reference to the Position values mentioned above and just uses horizontal/vertical values to change position of object in appropriate way - Am I correct ? :)

    JoeStrout - Thanks for clarifying the uses of "Axis"
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It doesn't know; you program it to do that, if that's what you want it to do. The names of the axes are arbitrary strings, you can call them "Flibble" and "Wakawaka" for all the difference it makes. What you do with the input is entirely up to you, Unity doesn't care. To be clear, it's not physically possible for a keyboard to have an axis (well, unless you want to say that each key is a vertical axis or something ;) ), and "X axis" is just the default and is not used if it's not relevant.

    --Eric
     
    Kiwasi and AdrianHil like this.
  8. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Yep, yep. Hopefully it's all cleared up for ya now :)
     
  9. AdrianHil

    AdrianHil

    Joined:
    Feb 1, 2018
    Posts:
    26
    Thanks guys for your answers and patience :) Now everything is clear for me. Have a great weekend! ;)
     
  10. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,954
    There is an analog keyboard out there... :p

    https://www.wooting.nl/wootingone
     
    Kiwasi, JoeStrout and AdrianHil like this.