Terrain Maps: A terrible (but awesome) way to make terrain traversal

Early on in my project, I typed up some placeholder code to deal with the player colliding with the terrain. Essentially, it did a check to see if the player was inside of the ground. If he was, keep pushing him up until he was no longer in the terrain. This sucked. Seriously, it was awful. When moving uphill, the player would slowly get pushed upward, and when moving downhill, the player would jitter around as he fell into the ground, was pushed out, and fell back into it. I knew I had to scratch this code right away and write something better. The result is a pretty awesome, although inefficient, terrain map. Basically, after the terrain is drawn onto the screen, a huge array is generated based on the height of the terrain. It goes through pixel by pixel in the X direction and stores the height of the terrain at that location. The game does a check to see if the player is inside the terrain, and if so, sets his position to the top of the terrain. The result is very smooth movement across terrain, like this:

TerrainThe movement up or down through the terrain is only as sharp as the terrain itself, because the player moves exactly along the terrain height. It works quite well, and hopefully it isn’t too memory intensive.

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Terrain Maps: A terrible (but awesome) way to make terrain traversal

  1. Pingback: Weekend Update | Kanro Games

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>