Walking around objects


Walking Around And Behind Objects

In our ongoing effort to make ZomdeadZ less crappy, we now let players walk around and behind objects, creating a more realistic depth effect. Here’s how we achieved it.

AABB Hitboxes and zIndex Updating

To manage how objects and players interact in the game world, we use Axis-Aligned Bounding Box (AABB) hitboxes. These hitboxes help us determine when a player intersects with an object, and based on this intersection, we dynamically update the player's zIndex to ensure they appear behind or in front of objects appropriately.

Assigning zIndex by Y Position

When generating the world, each object’s zIndex is assigned based on its Y position. This means that objects lower on the screen (higher Y value) naturally appear in front of those higher up. As players move, their zIndex is updated according to their Y position, allowing them to seamlessly move in front of or behind objects like trees or buildings.

Hitbox Offsets for Realistic Interaction

Objects in our game have hitbox offsets, making their interactive area smaller than the object’s visual representation. This allows players to walk behind a tree and be hidden or walk in front of it and remain visible.This feels natural and players can strategically use the environment to their advantage, such as hiding behind a tree to ambush or avoid enemies.

Conclusion

This system of dynamically updating zIndex based on Y position, combined with AABB hitboxes and hitbox offsets, adds a layer of depth to ZomdeadZ. Players can now interact with the environment in a more meaningful way, enhancing both gameplay and immersion.

Leave a comment

Log in with itch.io to leave a comment.