[Solved] How to give boxes falling gravity (WITHOUT PLATFORMER CHARACTER BEHAVIOR)

So I once asked how to give boxes a function of falling down if there’s no ground or other box for them to land on, it required using the platformer character behavior but I’ve ran into issues with it where I can’t keep using this solution.
It’s mainly performance, there will be so much boxes per level (minimum 100) and all of them having a whole player behavior just for them to only fall down is very overkill. and there’s an issue with the behavior itself where if a box is one pixel inside of another they will begin acting weird and move on their own until they both fall off the ground.
So, I was wondering if there is a way to make a box object fall vertically down until it lands on another box object or a platform WITHOUT using character behavior, bonus point if there are a bunch of boxes on top of each other and destroying the lowest one makes all the ones above it fall down until they meet a box/ground platform

1 Like

You should explain what you really want to achieve or people will give you solutions that don’t fit your actual needs.
Why do you want to pile boxes up?

Alright, I’ll try: My game revolves around breaking boxes to do different things, like giving you coins or special abilities, or getting a special reward for breaking all boxes in a level, that’s just the way it is, it’s part of the level design
I just want the boxes to have falling gravity where they go down the Y axis until it lands on another box or ground, instead of them being stuck in the air, not outright physics where it can go all over the place, just fall down vertically, that’s all

1 Like

Funny you mention not using platformer character behavior
Cause i once made it work exactly as you describe for other user
Using platformer character behavior

LMB to destroy block
RMB to create block

But since you don’t want it this way
I think you could add points below your boxes
Or simply offset in expression center Y point or bounding box bottom
To check if its in collision with a another box or inside it
You could even raycast

And if condition is not true simply apply force to your box to angle 90
Or add 1 to box Y position or maybe add 2 3 or 5 or 10 depending on your boxes it may vary

Good luck

1 Like

I tried raycasting and it almost got the results I wanted

Here’s the issue tho: See when I deleted that first box on the ground? The others above it didn’t fall because they are in collision with each other, when I removed that second one between the two they fell because they no longer are in collision with each other, same with the third one
This is the event used:


If you have any idea on how to make them fall regardless, then my problem is fixed, thank you

Ok something here is ultra wrong i cannot help you any further
Cause either we have bug or i am doing something wrong look
THIS

Works for detecting ONE stone (and it detects one i placed as first on scene)
So everything is here fine
BUT for it to work with other stones we need to use for each object
And IDK why but it simply do not work for any of them

I Have NO idea why it is not working since it should make it work for all stons
I mean that for each object event type
YET it does not

And without it nothing will work
IDK if gdevelop if it a bug (i did try ray cast and point inside object with same result)

I am kinda more sure i did something wrong than it would be a bug
But hardly i can see how i did anything wrong

I tried to think of anything but just couldn’t, even tho it’s literally one issue left which is boxes colliding with each other in the air, I’m kinda surprised something as simple as a falling object is hard to pull here without using a whole player behavior

Worst thing you can do WHICH will actually work
You see my events

This will draw circle on that point

Well you could create custom object and link it to each box

And now you would check collision of box with that collision object
And that would work 100%

I seem to have connected them, is this how it’s done?


Now I just don’t know what to do with the falling events, I’ve never used the linking events before, do I focus on the point or box?

Here’s my solution:

BoxDrop

It involved 2 box objects; one is the normal box, the other has a collision mask for just below the bottom row of pixels. I stick the box collision checking object to the box using the Sticker behaviour and hide it.

This is my BoxChecker collision mask (bottom row of pixels):


And this is the origin of the BoxChecker object, which is offset by 1 pixel up the Y axis. This is done so the collision mask (bottom row) is below the Box object it will be attached to:

The Box origin is at (0,0), unlike the BoxChecker object. The Box collision mask is the whole sprite.


The events:

1 Like

1st try what MrMen wrote
If that does not work for you then you read what i wrote below

Now all you need is check if your Point object is in collision with box
If it is then you do whatever you want to box
For example
If Point object is NOT in collision with box you add force to box
But for that you would need to place that point above each box and not below

OR maybe it will affect linked box
You can do this


Make sub event to this
And put there
INVERTED Point is in collision with Box
Add force to box

Or maybe you need to use NOT conditon

It worked! Thanks a lot!

I did consider using custom points that were just below the box object and checking if the point was in a box. The only downside I see with that is if the box is resting on another box, but the point is not within the lower box. Like when the top box is to the side of the bottom box.

1 Like

Because you do need 2 points to make proper check
OR you need to stretch attached object to the width of your box

But core idea here was 1st to get it to work
Then it could be polished