Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What parameters can I use with Unity Input.getAxis?

Tags:

c#

unity3d

Unity .getAxis(string name) seems to return the thought offset generated by user input (arrows, mouse or even joystick). The return values is conveniently in interval of <-1; 1> except for the mousewheel.

From various code samples I can see many ways of getting input, but there seems to be no actual name/input list. In my case, I want to enable zoom using wheel or PgUp and PgDn. Wheel code looks like this:

movement.y -= ResourceManager.ScrollSpeed * Input.GetAxis("Mouse ScrollWheel");

But what for page down and page up? And, in general, how can I know which names to use in this method?

like image 424
Tomáš Zato - Reinstate Monica Avatar asked Nov 03 '14 23:11

Tomáš Zato - Reinstate Monica


1 Answers

Input.GetAxis and Input.GetButton (as well as GetButtonDown and GetButtonUp) just return the state of one of the virtual input axis defined in the Input manager.

The return values doesn't need to be in the range [-1, 1]. Most virtual axes that represent an absolute value are represented by a value between -1 and 1. However there are axes that return relative movement like the the predefined "MouseWheel", "Mouse X" and "Mouse Y". They return the amount that axis has moved since the last frame.

The MouseWheel has some additional "problems". The delta value is taken from the OS. If the user has set the scroll wheel to advance 3 lines per "scroll unit", You will get values of a multiple of 3. If you manage to spin the wheel fast enough you might get values greater than 3 or smaller than -3.

There are no default axes for PageUp or PageDown, however you can add them if you like. But be careful, GetAxis will return the state of the virtual axis. So when you hold down the positive button you will get a "1" as long as you hold the button down. If you want to listen to events you have to use GetButtonDown / GetButtonUp.

However if you want to check a certain key it's usually simpler to use GetKeyDown / GetKeyUp which takes a KeyCode.

Something like:

if(Input.GetKeyDown(KeyCode.PageUp))
    movement.y -= 1;
if(Input.GetKeyDown(KeyCode.PageDown))
    movement.y += 1;

edit
If you want to know the commonly available key names, take a look at the Conventional Game Input page. At the bottom there's a list of most common keynames including "page up" and "page down". The input manager usually refuses wrong key names. So if you type one in, unfocus to input field and the value stays, it's correct.

If you set a positive button whenever you press the button down the virtual axis will "slowly" increase from 0 to 1 depending on the "sensitivity" setting. The sensitivity is like an acceleration factor. If you release the button it will return "slowly" back to 0 depending on the "gravity" value which is a deceleration factor.

If you setup a positive and a negative button, the axis can go both ways up to 1 when the positive button is pressed and down to -1 when you press the negative button. If "snap" is true it would snap back to 0 immediately if you press the opposite button instead of slowly going back to 0 and then start growing in the opposite direction.

The "dead" value defines the dead-zone. If the value of an axis is smaller than dead (or greatern than -dead) it will be treated as 0. This is important for real analog input devices which usually have some jitter around their resting position.

The remaining properties like "invert", "Type" and so one should be clear when reading the documentation.

It's possible to define two axis with the same name like the defaule "Horizontal" and "Vertical" axes. Axes with the same name are treated as one.

I think that should cover most of the Input Manager stuff.

like image 65
Bunny83 Avatar answered Oct 16 '22 18:10

Bunny83