Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In this video we're going to take a look at using the input manager of unity to map our user inputs
to our character.
For example I want to be able to move left and right based on the Andes Keys and up and down based on
my W.S. keys in order to do this we need to take a look at the input manager to check out the input
MANAGER We're going to go to edit project settings and you'll see here that there is something called
input and within the input we have what's called accesses unity by default provides us with 18 different
accesses that we can use to map user input and you can add your own.
For example you'll see there's things here that are jump in fire which are already mapped to things
like game controllers and the spacebar.
What we're interested here is the horizontal and vertical axis is if I check out the horizontal axis
here you'll see here that it has a negative button as well as a positive button and it's the left arrow
in the right arrow.
It also has an alternate negative button and positive button which is map to the HD keys.
So what I want to do is I want to use this access to move horizontally.
The next thing you'll notice here is that it has a name.
I'm accessing the horizontal axis and by doing that I can use a and d.
But what needs to make sense to me is how how do I use this to move my character with a D.
Well it comes down to what do I get.
What is this value.
If I were to do anything with this horizontal axis what does it mean.
So let's check out what's being returned here.
What are the things that the axis is.
Don't really tell you is what they return buttons are Easy buttons are boolean they're true or false
if you hit a button but what about a horizontal and vertical axis that determines if you're hitting
an HD key to move an object.
Well this is where it comes down to.
We need to store it in a variable in viewing what I'm going to do here for testing purposes and you
don't have to follow along with this but if you'd like to you can.
I'm going to create a public float variable of type horizontal or not have type just the name horizontal
I'm just you can name it whatever you want but here we have public float horizontal and let's call it
horizontal input.
The reason why it's a float is because I know that that horizontal input is going to return a float
value.
And what I want to do is I want to say the horizontal input variable is equal to the input manager which
is the input and then what was the hierarchal step to get to that access.
Well we go to input accesses and then we specify the access we want I want the horizontal axis encode.
You say input get access and then you open a parentheses and then we can pass in a string of the axis
name anytime we're working with strings you're gonna use quotation marks and we're gonna type in here
the horizontal axis if we save this and hop back into unity I'm going to close the input manager and
run the game and watch what values appear next to this horizontal input in the inspector you'll see
here that our character is not going to be controlled but if I hold down the left arrow it goes from
zero to negative 1 if I hold down the right arrow it goes from zero to positive 1.
Likewise if I hold down the 8 key or a negative on the D key is 1 if I'm not holding any keys the horizontal
input value is 0 using that knowledge we can use this horizontal input variable and the way we can use
this is I can basically I don't need to necessarily see it so I'm going to remove it from there and
I'm going to create a local variable that's only used inside of update and it's going to be of type
floats and it's going to be a horizontal input equals input I get access horizontal once I've declared
that variable I'm going to move this to the top
and then in our transformed not translate method I'm gonna say vector three dot right multiplied by
our horizontal input multiplied by the speed multiplied by real time.
And if I save this and we go back into unity like Unity compile and let's run the application I can
now move using my d key to go write a key to go left right arrow key to go right and left Cherokee to
go left and if I stop moving I stopped moving.
Now let's take a look at how that works right now we declared our horizontal input using what's called
a local variable of type float and we just set it to the input dock get access horizontal inside here
I included the multiplication for that.
So now we have vector 3 about right which is new vector 3 1 you know on the right multiplied by horizontal
input which is let's say 0 when I start out multiplied by our speed which is three point five f mortified
by real time if I'm not moving what's my vector if I'm not moving 1 times three point five becomes I'm
sorry if I'm not moving one times zero is zero zero times three point five is zero and zero times real
time is still zero.
So we're not moving the vector length is zero.
Now what happens if I hit the D key or the right arrow key horizontal input becomes one new vector three
one times one is positive one one times three point five becomes three point five and then three point
five times real time is meters per second I now move to the right three point five meters per second
likewise what happens if I hold down the eight key or the left Cherokee this becomes a negative one
and if we look at the math here we have vector three about right which is one times a negative one which
becomes negative one.
So now we're moving to the left negative one times three point five becomes negative three point five
and then Z for the rest.
So that's how the math is working underneath so as a challenge what I'd like you to do is figure out
how to move vertically we're currently moving left and right like this go ahead and add the second access
which is the vertical axis and go ahead and move up and down.
I'll see you in the Challenger view.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.