Issues with Collision Mask

So, I’m making a simple small game for myself to get myself into game making, but I’m having a problem with the hitboxes. So far, I have a character and spike objects (the character is flying via the arrow keys so there’s no ground), but I’m having problems with the collision mask. I applied a custom collision mask to both the character and spike objects, but both are still behaving like they have the default collision masks. Is this a bug or am I missing something? I would really appreciate knowing which it is and how to fix this.

A couple of potential gotchas :

  1. Make sure the collision masks are convex i.e. have no internal angles > 180 degrees. Failure to do so will result in the default large rectangular collision mask :

  2. If you have frames to the animation, make sure to share the collision mask with all the frames

Is this true? I’ve been using complex concave masks for years and never had a problem. Is there a reason (such as this is bad practice, or that GDevelop can’t handle angles less than 180 degrees)?

If you turn on “Debugging view bounding boxes / collision masks”, you will see any concave collision masks are not there, and replaced with a rectangle. And you can test it easily enough with 2 sprites…

I put on the debugging action and took the screenshots below. The concave red collision masks are there. Unless I’m looking at it wrong? I tested it with the player/dragon collision, and it doesn’t register as a collision unless the player hit within the concave dragon hotbox. :man_shrugging:

Something has changed - GDevelop used to (as in a few month back recently) revert to default image collision mask is a convex one was used.

But the convex collision mask isn’t accurate either. Here’s the events for the demo of a draggable object pushing round another object:

And here’s a short gif of the result :


Notice the collision isn’t detected in the define convex mask? But it’s also well within the outer bounds of the image.

I’m not sure what to make of that one.

1 Like

Just to be clear here: Convex masks are supported by the engine. Concave masks are not. The engine didn’t used to let you save concave masks at all, so not sure when that stopped happening, but as MrMen said they still do not work at all for actual collision detection logic. You would need to split all concave masks into separate polygons to make them all convex in order for it to work correctly within logic.

In some cases (platformer character behavior) even convex is ignored. Platformer charactees only use the widest point of the hitbox and the tallest point of the hitbox for a rectangular movement/collision hitbox.

Well, there’s a couple problems with this.
A) The mask is convex, so it can’t be the concave issue. For example, the spike’s collision mask is an equilateral octagon, yet it doesn’t work.
B) The “share with all frames” setting is enabled, so it can’t be that.

If it helps, one other detail is that currently, I have no animations for either the player character or spike object. Could that be an issue?

If you mean you have no asset/images for either object, yes. The engine requires at least a single asset/image/etc for any visual object (sprite/tiled sprite/panel sprite/etc) for it to work in logic.

This can be a single square in an image file, an image with only transparent pixels, etc, but an image file must be supplied and have actual pixels in it (not just an empty txt file renamed png, for example).

If you mean something else, more details are required.

Oh, sorry if I was unclear. I meant that I don’t have any proper animations for either. Both objects do have one image file each, but that’s it. That was what I was trying to say.

Just to cross off one more possibility, you are talking about standard collisions (the one with this symbol
image), and not physics collisions (which has this symbol image).

If you’re not using physics collision, could you post the events you are using to determine collision?

I am using physics collisions.

Physics doesn’t use the standard collision mask. It uses the collision mask you define in the Physics behaviour that you set for the each object.

Ok, but how do I change the collision mask in the physics behavior? I only know how to do it under ‘properties’

I’d question why you are checking Physics collisions.

Generally you let the Physics engine deal with collisions. If two physics bodies (object with physics behaviour) collide, the physics engine will work out the result of the interaction and apply the correct forces on each physics body. You don’t want to interfere with that process because the outcome can be ugly and unpredictable.

But, to answer your question :

  1. Choose Polygon
  2. Select the image of the object
  3. Click the + sign to add vertices, which you can drag around.

I just tested it out and it worked! Thank you so much! Hopefully the rest of development on this little game goes smoothly. I’m intending on it being the first game I ever complete, after numerous tries on other game engines, such as GameMaker Studio and Scratch. Again, thank you.