Tuesday, February 8, 2011

Collision Masking

Work continues on the alpha.  The built-in movement and collision routines with the main tool I'm using to develop FaeSaga in are a bit of a double-edged sword.  On one hand, it allows for rapid prototyping of what the game will sorta feel like when it is complete.  Collision detection can be powerful stuff, as it can handle per-pixel stuff automatically.  On the other hand, fine control of these routines often come with irritating caveats, or aren't available at all.  Therefore, I've spent most of today working on a replacement movement and collision routine for the main character.  (Video after the cut)



The main features of the new collision detection and movement are based around using 4 indexed detectors around the shadow by the player's feet.  The purpose of using detectors is for the collision to "feel around" nearby tiles to get a masking value which explains the sorta terrain the player is on or about to be on.  Not only does this make moving against walls much smoother, it also allows for the player character to get information from the tilemap in a much more descriptive way than it was able to before.  Each detector has its own "mask value" which are added up into a numeric mask to determine the sensor state, as shown in the picture at the top of this article.  Since the detectors are enumerated as the same type of object, in theory, I could use more than 4 detectors without much issue.  However, 4 detectors is plenty for our square-based Movement Permissions tilemap.

To test the new information the player character can get from the Movement Permissions map, I also implemented rudimentary jumping abilities in the new movement.  While the player character is in "jumping" mode, it can jump over blocks marked "Jumpable" in the MP layer, as well as water tiles.  Landing inside a tile marked "Jumpable" simply blocks movement as if it were colliding (so as to block off areas if you don't have the ability to jump), whereas tiles marked "Water" create a splash effect and rewind the player character's position to a safe distance away.

Water tiles are a type of jumpable tile, but assess a penalty if the player character is detected to be "in water".  This is determined again thanks to the new detector masks and its variable state, as seen in the picture at the top of this article.  If 3 or more detectors sense they are "in water" (the mask reads 7,11,13,14, or 15), then the player's position is reset to a "safe position" (rewound about 60 frames) and they're given a short invincibility period. This temporary invincibility does not allow crossing water without another penalty, so later on I will have to assess whether to temporarily make water tiles full barriers while the player is temporarily invincible, as sometimes the player can be respawned dangerously close to the water (although never touching it).

Demonstration video:


At around 0:08 you can see the collision detection working, without rough "stop and starts" or bouncing endemic to the default 8-directional movement.  The rest is just a demonstration of the various tile types.  The floating number is the detector's combined mask value for the adjacent water.

Please Share


No comments:

Post a Comment