How do I check if there's a collision at a position?

Basically, I need to check if there would be a collision at a position that’s relative to a given object.
For example: I want to check whether if Object1 collides with Object2 at the position Object1.X()-2. (If Object1 was 2 pixels to the left, would it collide with Object2)
There don’t seem to be any specialized conditions for this, so how do I do it?

If you want to check collision happens which side of an object, you can simply check:

If object1 is in collision with object2 AND object1.X() < object2.X() : object1 is collided with object2 on the right side

If you want to check if a collision is about to happen before the collision happens, you can check distance between the two object.

If distance between object1 and object2 <= 2 pixels AND object1.X() < object2.x() : collision is about to happen with object2 on the right side of object1.

Also don’t forget to use “For each object” event to make sure the condition is checked for every single instance. and actions triggered only on the ones that met the condition.

Doesn’t work right. I know I’m doing it wrong, but I’m not really sure how to do it right. Here’s the way I used it:

Basically, what I’m trying to do is determine whether there’s a wall 2 pixels away from the player, before moving him into a certain direction. I’ve noticed that when hitting solid objects in the platform behavior, the player object jitters, so I decided to program the movement and wall collision myself. I have to admit, I was previously using Game Maker and this is how you would program it there, however I do realize things will be different here. Perhaps the whole “checking whether there’s something before moving” procedure isn’t even necessary. Can you help me out with this and tell me how you would handle player movement and wall collision?

PS: There isn’t a “For Each Object Event”. Is “Pick all objects” the equivalent?

You don’t need to verify all walls, since only the one the player is currently colliding is the focus of your algorythm.

To make it work, I would try to make the wall’s collision mask bigger than the sprite. That way, the player will collide into it, before colliding visually.

You can also work with two layers, the collision one and the visual one (overlaping the collision layer).
You build your level with simple collision boxes, and you hide them behind a more visually appealing scenery.

Seems like a good idea, but wouldn’t this conflict with the platforming behavior. Like, if I program it, so that it doesn’t allow movement, when touching the wall objects, the player won’t be able to move, when standing on the ground, because it would be another wall object and the player would be colliding with it (I don’t want to create another object just for the floor. That can screw things up, anyway).

I was in the same position of looking for the equivalent of the place_meeting style check to avoid the player going part way into a wall before being detected. The solution I went with was to have a dedicated “wall check” object that is continuously positioned in front of the player and check for collisions between that object and the wall, rather than the player and the wall. You then just set the horizontal speed of the player to zero if the wall check collision occurs.

If you are trying to stop the player precisely in-front of the wall by 1 or 2 pixels, I’m sorry but I don’t have the solution you looking for. In theory, you need to pick the nearest wall and it distance from the player and you need to reduce the movement speed of the player according to distance to make it stop precisely right in-front of the wall. Game Maker got better solutions to do something like this from scratch. Personally, I had no success with doing it in GDevelop so I would love to see as well how it can be done in GDevelop.

What you could try though to see if it helps, is check the collision between the player and the wall and use the “separate two objects” event to move the player away from the wall when it is collides, and when it does, the same time reduce the player movement speed to something like 0.1 to make sure it is not stops completely but make it movement less noticeable.

So try something like this:

Really, you should. It is a lot easier to detect if the player is colliding with floor or wall if they are separated objects. If you are using the same sprites for wall and floor just create a copy of the wall object , name it floor and create a group called “platform” and add both object the floor and wall to the platform group. If you want to do something to both, you can refer to the platform group, if you want to do something only to one of them , you can use the object name. Like if you want to check if the player is on the floor, you can simply check collision with the floor object, if you want to check if player is in collision with anything, you can simply check collision with the platform group.

Well, thanks for the advice. This whole thing is complete bullshit, though. All this trouble, just to have wall collision without movement glitches. I’m gonna make a thread in the feature request board. Nobody should deal with this, especially when every other game creation program handles wall collision much better.

Just stumbled upon your thread. I have found a bug some time ago that could be related to your jitter problem with the platformer behaviour.
Have you tried playing with the accelleration value to see if a higher value solves the jitter?

Huh… You seem to be right. Setting the Acceleration and Deceleration to incredibly high numbers (8000 seems to work best in my case) do remove the jittering. Thanks! I was actually gonna follow MattLB’s suggestion and I figured out a system with two checking objects for the left and right sides, but this works too. However I do have a question: would having such high values eat up more CPU resources? I know they wouldn’t eat up much, but I don’t know what GDevelop does to calculate how much to move the object and I want my games to be playable on even really low-spec computers. Also, this works great for the game I want to make, but it wouldn’t work in cases, where the player would have friction (like if the player was stepping on ice) and the Acceleration/Deceleration values need to be lower.

I created a bug report on github:

(can’t say anything about the performance impact)