From the course: Unity 5: 2D Movement in an RPG Game

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Move the player

Move the player - Unity Tutorial

From the course: Unity 5: 2D Movement in an RPG Game

Start my 1-month free trial

Move the player

- [Voiceover] At this point we have everything we need to actually move the player. Let's open up the MapMovement Controller, and we are going to delete the Debug.Log statement, and replace it with MoveTo, and here we'll supply the tmpIndex that we calculated earlier. Let's save this and run our game. And now if you hit the arrow keys, you'll see that we were able to move the player around the map, but it doesn't look very exciting. Let's add some animation as the player moves from one tile to the next. To do this we are going to need to go back into the MapMovement Controller and at the top of the class let's add the following fields. We'll start with a public float for speed and we'll set this to 1f. Next, we'll do a public bool for moving. Then, a private float for moveTime, and finally we'll add a private Vector2 for a start position and an end position. Now let's create a new private update method. Inside of this method we want to test to see if moving equals true. If we are…

Contents