Option to check collision on individual sides.

At the moment we can check collision between objects as a whole.
Would be great if we have the option to check collision on left side,right side,top and bottom of an object.

For example :Mario a well known platformer game on the Nintendo platform.
If Mario collided with the left or right side or the bottom of the enemy,Mario is died but if it collided with the top of the enemy (jumped on enemy) the enemy is died.

At the moment there is no built in function in GD to make something like this.Of course we can work around by adding objects to all side of the player (Mario) and check the collision between these objects and the enemy,or we can add objects to the enemy and check collision between the objects and the player.Not a big deal,but I think it would be great if we can see under collision more options like:

Collision anywhere
Collision left side
Collision right side
Collision top
Collision bottom

So we can choose if we want to check collision anywhere or on a specified side of the object and so we can choose what action to take depending on where the collision is happend,happening.

Agreed. Also then keeping track of if character is on ground would be easier.

If bottom side is colliding and not top, character is on ground so he can jump.
If top and bottom is colliding, character is being crushed (keeping Mario example, by Thwomp)
Same for left and right collision.

Which part of a sprite do you consider to be, for example, the bottom ?
I mean, when the bottom part of a sprite is overlapping, let’s say, a ground, there are also pixels on the left and on the right that are overlapping. We need a better description of a side before going any further with this feature request.

Well, as far as I know the original\default Direction is always is the right side of the object.
This way we already know which side is the right side, so we can go from there around the object in a square shape or octagon (I guess) :slight_smile:

That’s not really the problem here: You can without problem add a condition to check the direction of an object.
My question was, when a sprite is overlapping another, how do you make the difference between sides? ( When a character colliding with a wall from the left for example, there are a lots of pixel which are overlapping, and in particular lots of pixels in the right part of the character, but also lots of characters located at the very top or the very bottom of the sprite ).
So I need a better definition of the “side” of a sprite before doing anything else.

I don’t know anything about engine programming so I don’t know if it helps,but I have mentioned square or octagon because I could imagine like this:

As you can see on the picture we could use 2 layer collision check.First layer (yellow) detect the side,the second layer (black) detect the actual collision.In any case it should be able to detect which side is colliding thanks to the shape of the first layer.
But I don’t know how complicated can be on programming side :imp:

It gets rather more difficult than that when you consider that most sprites are not squares or octagons. I think this achievable by having separate collision masks for side detection that you just draw on called MaskRight, MaskLeft, MaskTop, bMaskBottom. It is a little time consuming to draw 4 extra collision masks for an object if you want to be able to detect side collisions, but I don’t see any other day to do it.

Yes,maybe can’t see on the picture but this is what I meant, separated “side detectors” around the object.

If you find it difficult to implement such a thing that detects collided sides automatically, maybe can be an easier solution to let people to select and name areas of the object manually by drawing (selecting) polygons or draw a box around the area, whatever. For example I could select any area of the object and name it let say “a” and I could use events like: If object1.Area(a) is in collision with object2.Area(b) then do something.
Maybe it can be even better because this way we could check as many areas individually as we want not only 4 sides :slight_smile: