Tileset collisions for diagonal surfaces

https://wiki.gdevelop.io/gdevelop5/objects/tilemap/#handle-collisions

Since tilemaps are still a semi-experimental feature, I’ve been wanting to hold off mapping for my game, but now I’m reaching the point where I want to be able to make my maps as well. Given it’s both my favorite editor and the only one that supports collisions, I use Tiled. The process is actually very simple and feels complete as described by that article, but there’s one thing I’m bound to have an issue with.

Is it possible to have collisions on diagonal surface? The collision mask appears to be automatically generated using the class of tiles, which is a great approach but won’t handle non-straight surfaces. I worry this may be a limitation with no workaround, but just in case I wanted to ask.

This for instance has a lot of diagonals and a circular set: I don’t expect the round parts to collide on their own, but was hoping at least 45* or 22.5* surfaces could work out-of-the-box somehow.

At very worst if I really need to, I may use a rotated box sprite for such collisions… I really don’t want to as using two collision systems feels like an ugly hack. Same as using just boxes, I’d rather every edit done to my map in Tiled is applied automatically in GDevelop without me having to move everything.

To clarify: Collisions are not automatically generated by the class. You define what each class means when setting up the tilemap collision object in GD5, but you still have to manually draw the polygon for each tile in your tileset within Tiled’s collision tool.

The only exception is if the entire tile is a colliswr (full square). It is phrased a bit oddly, but that is what the “When the whole tile must be part of the mask, there is no need to define a square on it. GDevelop will create it automatically” Line means in the documentation page.

Note that tileset collision limitations are the same as sprite collision limitations. Each tile polygon must be convex (no indents).

You can look at the Not-a-vania example to see how that tilemap has slopes.

Hope that helps.

1 Like

Aha, so there is support for drawing custom collision shapes in Tiled! Thanks… it might help to make this clearer and show a screenshot of it on that wiki page: I was left with the impression you only define the class, which works as a yes / no boolean and can only generate a box collision.

Unfortunately I’m running into a few other issues with tilemap collision masks and the Platform behavior. Please let me know if I should report any as bugs and there are workarounds:

  1. When the player is pushing against a wall, the “current horizontal speed” conditional keeps reporting their full walk speed even when they are stuck. When you’re stuck pushing against a solid sprite by comparison, this speed will drop to zero accordingly.
  2. The “point inside object” conditional fails to detect when the point it indeed in the collision mask, it seemingly returns true when in the rectangle of the whole tileset. By comparison the “collision” conditional (collision between two objects) seems to work fine at least.
  3. Enabling “ledges can be grabbed” in the Platform behavior doesn’t make edges possible to grab: Just like the speed reporting problem, that only works when used on a sprite.
  4. The Light Obstacle behavior works but causes a HUGE performance drop the moment you add a light. I presume it’s due to each tile generating an unique box and GDevelop having no optimization system to reduce their count. Are there any hopes of this improving?
  5. A less significant one but may as well ask: When enabling “debug mode” to see collisions in-game, collisions stop working and the player falls right through.

I can’t comment on all of these, but heres what details I can provide.

“Debug mode” is meant for the IDE, not in-game (That’s the “Show visual debugger” action instead), but also I cannot reproduce this issue. Enabling it/leaving it enabled in the object within the Not-A-Vania example doesn’t cause any falling/collisions not working.

It seems to work fine for me.
Events:


Visual Debug on:
image
image

Visual debug off:
image
image

I can reproduce these two. Not sure on what the expectations might be/whether it can be fixed, flagging @davy to see if he has any ideas.

Unfortunately, as far as I’m aware the lighting system was done by a Google Summer of Code participant, and they’re no longer active in the community. I don’t know of any plans to enhance that system. (That doesn’t mean there isn’t/won’t be any, just that I’m not aware of any).

1 Like

Interesting: I can clearly confirm that enabling “debug mode” on the tileset collisions object causes the boxes to show but also collisions to stop working, they work again once I disable that setting. If this is relevant: I have the tileset collisions object on the base layer with everything else, Z-Order 1 for it and 5 for the player… tilemap and tileset are different json files (not bundled).

As for point detection, it seems I misunderstood where the center point was located: I thought it’s at the bottom of the sprite but it was in fact in the middle, hence I had to use Player.CenterY() + 16 to get it out of the object for a proper test. The following statement now works:

Please let me know on the speed detection and edge grabbing issue if anyone has more info: Based on whether they’re bugs that are sure to be fixed I may have to change a few design choices.