Tuesday, December 30, 2008


On Day 9 of MMORPG development I turned the player into a grey box and allowed him to walk around. To do that I had to implement collision detection, which is easy to do for tile based maps.

The walking was handled by four methods in the Character class: walkUp, walkDown, walkLeft, walkRight. When a method was called (probably by a key press), it checked if the player would collide with the tile the player was about to walk on and then accordingly moved the player. The collision system looks something like this:

Each tile had four edges, each of which could be walk-through or not. To move the player the walk-methods had to check if the corresponding wall on the current tile was walk-trough and if the corresponding wall on the next tile was walk-through. If this was not the case, the player was not moved. In the above case the player (black dot) wants to move left. The tile the player is on allows that but the tile the player is going to move too doesn't so the player isn't allowed move.

I had to make an additional collision map for my current test map. The collision map stores the collision values of all four walls of each tile in the map. It was a simple arrays of 0's and 1's, where a 1 stands for collision and 0 stands for walk-through.

Each time the player moved his height he had too be properly adjusted so that if he moved to a higher tile, he doesn't sink into the floor and if he moved to a lower tile, he doesn't float above it. This was also handled by the four walk methods. The methods simply found the average of the tiles Vertices and used that as the players height. This has some disadvantages on very very steep tiles but I'm not planing to let the player walk on top of tiles with more than a 45 degrees slope.

It's kind of great to be able to walk around the small test world and I'm happy because the MMORPG is now a big step closer to being finished.

No comments: