Optimal design of tile based hazards

Godot Version

v4.5.stable.mono.official [876b29033]

Question

There are a bunch of ways to approach this problem, and I want to know which one is the most effective and hassle free. I especially want to ask this question because I might not know all the methods.

By tile based hazards, I mean things like classic spikes in platformers. One spike or set of spikes is a single tile, and you can place as many of them as you want.

  1. Build single set of spikes as a scene, and then drag and drop them into the game scene. It will be kind of annoying to build levels that way, and you risk a situation that when player touches two collisions at once, they will receive double damage. I’m not sure if you can make a safeguard in code.
  2. Option one but add the scene to tile map layer and just place them like tiles. Now levels are easy to build, but the issue from point 1 persists.
  3. Place them as tiles, not scenes, and use tile map metadata. Solves previous problem, but you have to check for the metadata in loop on player’s end, which is not really perfect solution.
  4. Place them as tiles, not scenes, and manually place Area2D (damage zone detector) on the set of tiles. There should be no technical issues here, but manually placing Area2D everywhere would be tiresome.

Why would you need to check metadata? Just properly setup the collision for the tile.

1 Like

Afaik you need metadata to inform the game that those tiles do something special (like dealing damage, since tiles can’t have scripts attached to them to use stuff like OnBodyEntered). Collision alone will only make sure Player doesn’t clip with them.

Area’s body_entered and body_shape_entered fire on tilemaps:

Stick an area underneath player’s character body, define colliders in the tileset, setup collision layers and you’ll get a signal when the player lands on a spike.

2 Likes