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
English
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
Now that we have a starting position set for when we run the game let's go ahead and take a look at
how to move our player along the x and y axis.
If I select my player and focus in on it I'm going to position our anchors here so that I'm on an x
y plane and what I want to do here is I want to be able to using the WC keys move along the x and y
plane as well as the vertical plane.
And if we actually select our player and look at that you'll see here that as I use the move tool and
drag it to the right we're increasing our position on the X in the inspector.
And as I move it to the left we go negative.
Likewise if I go up and down you'll see here that the y value of our position in the inspector is changing
relative to where I'm dragging.
So what we want to do is how do we go ahead and manipulate movement through code.
Obviously we're going to be dealing with our transform and something that's going to affect the positioning.
So very similar to how we can access properties and variables of transform.
We can also perform function calls that will translate or manipulate objects.
Now the process here that I'm doing is called translating and Unity has a default set of methods that
are provided to us to translate objects in order to learn more about this.
We're going to learn how to use and read the scripting API.
The reference manuals and scripting API of unity or how you're going to solve your own problems what's
important to learn is how to research information and how to read documentation.
So what I want you guys to do is go ahead and select your player and look at your transform component.
There's three icons here to the right.
This first icon that has a circle with a question mark in it is the reference manual for the transform
component.
If you click that it's going to open the scripting API you'll see here that I clicked it and now we
are on the transform reference manual which basically would tell you information about the transform
component.
There is information about everything inside of unity.
It's all documented inside of the unity documentation that shifts with the editor.
Now here you'll see the transform component determines the position rotation and scale of each object
in the scene.
Every game object has a transform and that's important to remember every game object has a transform
and every transform is a game object.
You can use those terms interchangeably.
You can also access everything about a game object through the transform.
For example if I wanted this mesh render or this cube filter or the box collider I can get information
about it from the transform and then getting a component which will cover later in working with it.
So let's take a look back at the documentation and what we're going to want to do here is look at the
scripting API which will have code examples for what we can do to the transform so let's type and transform
and you'll see here that we have the position rotation scheme of an object.
Let's select that class and it's gonna give you information about the object.
Now what happens when people are introduced to scripting API is they get so caught up with the code
examples well we're using the scripting API for is for a description of what this function does or method
does and then also the syntax.
That's all we care about.
I don't care what the example is and I don't want to get lost in what their example is.
I just care that I have the syntax correct and I know what this function does.
So let's take a look here.
You'll see that these are some properties which are also like variables and you'll see here that they
have things such as the position of the transform that you can get which we already know as well as
the rotation and then a few others.
And if we scroll down here you'll see that we have public methods and functions.
And that's another thing that's used interchangeably functions versus methods in C sharp that the exact
same.
So if we look here we have some public methods in one of those methods is at the bottom here called
translate and it says moves the transform in the direction in distance of translation.
And if we select that you'll see here that we type out transform that translate.
And if we read the description here it says moves the transform in the direction and distance a translation.
And then if we look at the code example you'll see here they're just using the class that inherits model
behavior.
That's what lets us actually drag and drop the script onto an object they have update and then hear
they're typing in lowercase transform dot translate.
So they're getting a reference to the object the script is on dot translate and then they open a parentheses
and they type in some information.
And this is where typically people get lost.
I don't care what they're doing past this.
I just need to know that hey I have to type transform and then dot translate and you'll see here that
this is also what I should see it should tell me that I can pass in a vector 3 translation so let's
hop back into unity and actually work with this inside the update.
I want to access the object I want to move.
That's our player.
We're on that object already.
So I can access my transform from here.
I can say dot translates and I'm going to open a parentheses just like the documentation said from here.
Let's read out towards it.
It's going to move the transform in the direction and distance of translation and I can pass in a vector
3 translation.
Now for this example I'm going to type in here.
Vector three dot right.
And I'm going to end it with a semicolon.
Every line of code ends with a semicolon.
Let's go ahead and save this.
Hop back into unity.
Unity will compile and then we can go ahead and run the editor and you'll see here that our player is
just going to zoom to the right and you'll notice here in the inspector that the position is constantly
updating very quickly now before we take a look at this.
Let's talk about why I didn't use a new vector three because 100 percent of the time.
What happens if I see a vector three on supposed to use a new vector three.
Well that vector 3.0 right is a predefined template that's provided from unity.
That is the exact equivalent of saying I want to go one unit to the right.
I want to stay where I am on the z axis as well as the y axis.
So we put 0 4 y 0 4 Z and then I close it off and keep in mind that every open parentheses means a closing
parentheses I save this and this is the exact same thing as typing in vector 3.
Right.
If I wanted to go to the left I could simply just make it a negative value.
So here we go off to the right.
And we're constantly moving.
If I wanted to go left I could just changes to negative one or I could say vector three dot left.
It's going to assume that it is a default setting of one that you're looking for in the next video we'll
take a look at why we move so quickly to the right and what we can do to slow it down.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.