Track player movement on tiles

Keyboard Shortcuts

In this video Jesse Freeman shows you how to set up a delegate callback that fires when the player enters a new tile. This can be used for letting the game engine know when the player has finished moving as well as knowing what action to do based on the type of tile the player is currently on. It will be critical to capture these tile events later on in the project.

- [Voiceover] Now that we're moving our player…around the map, we're gonna want to get events…that let us know when the player lands on a tile,…and what that tile type is.…To do this, let's go into our Scripts folder…and open up our map movement controller.…At the top of our class, we're going to add…a new public delegate.…Its return type will be void,…and we're going to call this TileAction.…And inside of this we'll pass in an int for the tile type,…which we'll get from the auto tile ID.…

Next, let's create a new public field below this…that's typed to our tile action,…and, we'll call this tileActionCallback.…Now, in order for this to work,…we're going to fire this event…when the player lands on a tile.…The first place we're going to do this…is in the move to method.…Let's look for the condition where we test…if animate equals false, and set the transformed…opposition to the new position.…

Since this gets triggered immediately…when the player moves to this tile,…let's do a condition to see…if the tileActionCallback does not equal no.…

Resume Transcript Auto-Scroll

Author

Released

8/8/2016

Learn how to move a player on a tile-based 2D map and use that movement to trigger events—creating a gaming experience similar to classic RPGs. In this course, Jesse Freeman builds upon the lessons learned in the Unity 5 2D: Random Map Generation: adding a player, moving the player from tile to tile, and making the camera follow the movement, as well as triggering events on the map. Jesse also shows how to add a "fog of war" effect that reveals parts of the map as the player moves around and explores, and how to detect and update the artwork for visited tiles.