Day 10: Fixing the physics

January 13, 2010 by pekuja · Leave a Comment 

Well, yesterday I worked on the physics, but they were still a bit broken. Now I feel like they mostly work like they should, although the code is still a bit messy. Yesterday, the character would be able to stand on walls, because the collision check saw the tile right next to him. I eventually fixed this by making collision checks and checks for whether the character has walked off a ledge two separate things. Before I was running into the problem that checking outside the character was wrong for collisions, but checking inside the character was wrong for standing. While I was at it, I got rid of all internal state for the state machine states (yo dawg), and instead store all relevant information in the player character’s object. Another thing I realized I needed for the collision detection, was checking which direction the character hit a tile in. Basically checking whether the tiles being checked against have changed, and in which direction, so if the character moved over a tile boundary on the left, and is now in collision with a tile, we assume that it was a horizontal hit, which currently will bump the character back right a little. If the character instead had crossed a tile boundary on the bottom, we would assume the character just landed on a tile and change him to a standing state.

About pekuja

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!