YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

Checking for collision with tilemaps, should also return the tile #7887

Open jack27121 opened 1 week ago

jack27121 commented 1 week ago

Is your feature request related to a problem?

Say you check for collisions, you check for a tilemap, if there is a collision, you get the specific tilemap, but not actually the specific cell in the room you collided with. So if you wanted that specific tile, either to get it's rotation/flip/mirror or it's index. You have to do some extra math to figure out it's position, and then you can get it with tilemap_get_at_pixel

Describe the solution you'd like

i'm not sure on the best way to handle it, it could be a completely new collision function specifically about tiles. or all the current collision functions, returns the tile id along with the tilemap

Describe alternatives you've considered

if you're working with a player, with a large hit-box, and you collide with something, you can kinda guess the tiles location, by taking the player pos + it's speed. Though if you were for example walking nearly parallel to a wall, and then bump into it, you would get the position in front of you, and not the wall position on the side. So then that approach does not work.

The best you can do is, find every non-empty cell around the player when there's a collision, and pick the closest one. And hope it's the right one.

Additional context

No response

tabularelf commented 1 week ago

A suggestion I've made on Discord, is to have a unique reference to the tilemap id handle be generated. But with some metadata attached on top that can retrieve tile index information. At least theoritically, this should reduce any issues with trying to change the function as how it works now.

i.e.

// Will return unique tilemap id handle, or noone with no collision. Ideally, same tilemap id will be stored in this unique handle.
var result = instance_place(x, y, tilemap); 
if (result != -1) {
   // This will either build & return a struct containing the tile index properties and cell x/y. Or undefined
   var data = tilemap_get_tiledata(result); 
   do_stuff(data);
}

I feel this might be more pratical ^^;