How to make box have gravity (falling down)

How do I make boxes have gravity? I’ve been using the Platformer character behavior for them but the result isn’t quite what I want.

How do I…

Give boxes gravity so they fall when either they aren’t on the ground or on other boxes

What is the expected result

Simple falling downward for boxes, doesn’t have to be downward physics.

What is the actual result

It does sorta work at first but for some reason, the boxes keep glitching on top of each other and sometimes even start falling from the top when they shouldn’t, at first the collision wasn’t the full image, but I re-did the boxes and now the collision is the full image, same result, and this is an issue since the game heavily depends on a lot of boxes being on top of each other

Video Example

Is there a better/easier way of doing this?

Why not add force toward angle 90°
With conditions
INVERTED box is in collision with ground
INVERTED box is in collision with box

But i think your box would get stuck since they would collide with other boxes
I think there would be trick for that but for now i have no idea of any easy solution
Either someone else would come here with one such or give me some time

Yeah I did try this with the adding and stopping forces and it worked until I realised the boxes in the air don’t fall because they’re colliding with each other even though the last one isn’t in the ground, this is the one thing stopping me rn, I can’t think of a fix for it, take your time

Muhahhaha
I just made build platform game
Right click to create tile
Left click on tile to remove it

Disabling default controls is crucial here
You add to your box platform character and platform object


Funny, this is the exact same method I used that made me come here, the issue still remains from the moment the boxes slightly touch each other
https://cdn.discordapp.com/attachments/576553475337486351/1268639703780032665/2024-08-01_21-38-58.mp4?ex=66ad284b&is=66abd6cb&hm=e5a1a5b8cf5cb9e7b7d689bc784e8e294fcbb1b459613c55820df6c279bd0955&

Take 2
Box object

Ground object have both physics and platform object behaviors

Where all i did was add to both physics 2 and for ground object i changed type from dynamic to static

Gaps between tiles are there because my image is not perfectly stretched as image
It have empty space

Tried it, it breaks the system, the character now can go throw them and can’t jump on them to break it, whenever they’re broken they fall into places when I just want them to fall vertically, nothing horizontal, and I already use a physics object for box pieces that show up when a box gets broken, now instead of falling off-screen they remain on the ground, oh yeah the gap is still there, even if there is no space in the image.
I think the forces are the best approach, but it just needs a solution for when boxes are colliding with each other, something like the “If player is on platform X” condition for the PlatformerObject, instead of the collision condition

Wait a sec
I just noticed what is the problem look


I can stack A LOT of tiles on top of another
ONLY way to make them start to sink
Is when you place one tile inside another
Even if they overlap 1 pixel

So i wonder
How many boxes you are actually trying to stack on top of each other?
Cause there should never be issue unless you allow one box to invade space of another
And that is again using platformer object and character behaviors for tiles

I think I get the issue here, so in my game if the player breaks boxes and dies without getting a checkpoint, the boxes would re-spawn where they got destroyed exactly, and I need to have that respawn function so I’m not sure if I can rely on character behavior if it breaks this easily

When objects are created disable their platform CHARACTER behavior
Use wait like idk 1 or 2 secs and then enable it
That should fix the issue
Cause to my understanding whole issue comes from the fact they are NOT created all at once but like everything from top to bottom
So picture this
IF you have box on the left and box right from it
Then under 1st box on the left you have another box
Then going from order of creation they always be spawned at
1 one on the left
2 one on the right
3 one under the one on the left
SO something like
1 2
3
Instead of
1 3
2

So when 1st is created it already starts to fall because nothing is below it even for one frame and when one under it is created it is already overlapping one above it

SOOOOOOOOOOOO if you would disable platformer CHARACTER behavior when you create them they would NOT fall
And if you enable it like i said after 1 or 2 secs where they would be already created by that time then you would be perfectly fine

Tried it, it still happens because you can destroy the boxes after they fall out of their original position, so let’s say you have 3 boxes on top of each other, you destroy the lowest one and the two start falling and after they fall you destroy them, they would respawn inside each other

Wait what we are talking about
Cause i was sure you are talking about IF player dies then you respawn boxes at current position of these boxes WHEN checkpoint was reached
Or am i wrong?
If so then all you need is

At least i was expecting you are using it to save all boxes position at the moment checkpoint was reached and then load them back when player respawns
For that you would 1st delete all boxes THEN load them

So i do not get how 1 box can go inside another in this scenario
Or you are doing something else?

I mean one crucial component would be to place checkpoints far enough so player can’t destroy any box while reaching checkpoint

Oh, it isn’t exactly like that, when a box is destroyed, the events get the X and Y position of it WHEN it was destroyed, not its original position, I asked here before for a box respawn system and I’m using this without exactly understanding it, but it works


I guess the solution is for it to store the X and Y position of every box at the start of a scene, I just tried this but they now respawn regardless if player destroyed them or not

How you respawn them does not matter for now
What matters is when you save and load their current positions

I understand that you save each time a box is destroyed am i right?
Cause that is something you should NOT do

You should save pos of each box at some checkpoints you place on level
And then when player dies delete all boxes and load them from that save

Well yeah but a player can die before the first checkpoint, would it be possible to make it save the pos of every box in the level at the start of the scene? and also, would it affect the boxes that got destroyed? Like, player destroyed some boxes and found a checkpoint, I wouldn’t want these boxes to spawn again if he dies

How about make checkpoint an invisible one where player spawns at beginning of the scene or simple perform save when level starts
That would fix the issue

Okay, I could do with that
I guess it should go like this:

  1. Remove the saving of the boxes pos from the destroying boxes event
  2. Make a hidden checkpoint at the player’s spawn position and have it save all boxes positions
  3. When I reach a new checkpoint, have it clear the array so they won’t spawn again?
  4. When player dies, delete crates and spawn them again?

Nevermind, I tried and don’t understand what to do, they don’t respawn, what am I supposed to do with these?
Event for reaching checkpoint and respawning


Event for destroying a box and saving its pos

The counter and destroyedboxes variables are for a box counter that goes up when a box gets destroyed, and when a box respawns the value subtracts

Hold your virginity i think i got it by the ass i just need to test it out so you don’t come back here telling me it is not working

Muhahhhaa

Pay close attention
In save you can save either by touching skeleton or pressing 2 and it will do it automatically at beginning of scene

In load you will load boxes by pressing 1 and automatically at beginning of the scene

Press 3 to delete boxes
SOOOOOO

At any given moment you press 2 then 3 then 1
no matter if boxes are falling or are they already are stacked and not move

OR you could go to skeletons on the right touch one then press 3 and 1

BTW just for your info
That wait action 0,02
IS doing all the work
I forgot in gdevelop sometimes crap happens too fast
And you need to add at least one frame of delay
Same trick is useful when you make custom cursor for your game
And you want to hide your actual cursor
Sometimes it won’t hide
Then you just make
At beginning of the scene

Action
wait 0,02
Hide cursor

And it will always work
Same trick can be used in A LOT of cases

Have fun