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.

Reposition the player

Reposition the player - Unity Tutorial

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

Start my 1-month free trial

Reposition the player

- [Voiceover] Now we're ready to position our player at the castle when we start our map. Let's go back into the RandomMapTester and find the method where we create our player. We're gonna need to change the values of this Vector3. Just above where we set the position, let's make a call to our position utility. Here, we're gonna call CalculatePos and we're gonna pass in the map.castle.id. This will return the unique ID for the castleTile. We can use the map's columns value as its width and we're gonna use out tmpX and out tmpY for the X and Y position. Now, just like we did before, we're gonna need to multiply this X and Y position by the actual tile size. These values are only being calculated based on how many tiles exist in the map. They don't take into account the actual size of the map's tiles. So if we want this to display correctly inside of the scene, we're gonna need to account for that size difference. In order for us to multiply the tmpX value, we're gonna need to convert…

Contents