godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.08k stars 69 forks source link

Tilemap collision detection. #7244

Open ChknNugz opened 1 year ago

ChknNugz commented 1 year ago

Describe the project you are working on

I'm trying to make a 2d platformer/dungeon crawler game where your a soul imprisoned in limbo (in the lore of my game is a grey area betwene life and death), the game is going to be built with a tile map that has a visual wire system similar to minecraft redstone (which results i got so far look promising). Currently im struggeling to implement a wire imput system, namely the button.

Describe the problem or limitation you are having in your project

But i hit a brick wall working on the wiring system when i got to pressure plates and switches which would be the input few of the only inputs of the wiring system and i can't figure out how to get the tile map to detect/ return overlapping areas in the tilemaps collision mask.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I would like a method/function similar to get_colliding_bodies() or more preferably get_overlapping_areas() with the area 2d and other collision/physics classes/nodes in the tilemap class but also returns an array of tiles that are involved with the collision.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

extends TileMap

func _physics_process(delta := float) -> void: var overlapping_areas = get_overlapping_areas() for i in overlapping_areas: print(i)

If this enhancement will not be used often, can it be worked around with a few lines of script?

I add a work around but it would be a annoying inconvenience having to create a new physics layer for the tilemap alone and applying it to all my objects that occupy the "solids" physics layer. (In my program, the solids physics layer is a layer that all physical entities could collide in.) and having to remotely call a function from the tilemap script in the object scripts. A more local method that is prebuilt would be nice to have.

Is there a reason why this should be core and not an add-on in the asset library?

It should be a core implementation because the tileset has an unusable collision mask property that you can edit and sort of work with. This makes projects that use custom collision behaviour regarding the tilemap such as destroyable tiles so much more easy to implement.

KoBeWi commented 1 year ago

I think for pressure plates and switches using scene tiles would be better.

ChknNugz commented 1 year ago

I think for pressure plates and switches using scene tiles would be better.

The issue with that is, im trying to avoid using scene tiles because im afraid that it could slow down my game having hundreds of collision nodes (area2d) having to update every 1/60 a second. Using the tilemaps singular collision object was my work around the issue. For now i am using an extra physics layer for pressure plates and levers alone and remotely calling functions from local bodies that collide with said pressure plates and levers.

KoBeWi commented 1 year ago

Currently the TileMap is not a singular collision shape either; shape merging is yet to be implemented. It's a single body though. I think having hundreds of areas should perform just fine, depending on how many bodies collide with them. Or you could use single area with multiple shapes. Or in worst case, PhysicsServer directly. But I guess TileMap is easier to use.

ChknNugz commented 1 year ago

I got the system working a while ago but would still make a nice feature