How To Move Two Objects Away From Each Other When There Is Collision?

Hi,

I am stuck on the following:
When two moving objects collide have them move away from each other.
I tried “Bounce” but only one object moves correctly?

Any ideas on how to implement the above?
Let me know, thanks!

Jesse Lee

There are a few different ways to do that - there is an action “separate objects” that will simply “snap” the object to a position that isn’t colliding anymore.

If you want objects with momentum that bounce off each other, you could give them the Physics 2.0 behavior which lets you define a bunch of physical properties and then moves them accordingly during the game.

Hi,

Thanks for the reply.

I tried Physics 2.0, but now the enemy does not “Bounce” on the floor, walls, & ceiling?

Can I have Bounce and Physics 2.0 on the same object simultaneously?

Jesse Lee

No, you should only have one or the other:

I haven’t used that extension so I’m not sure if it will accomplish what you want. But, with physics engine you can achieve bouncy balls by setting their properties the right way. It can take a lot of tweaking settings to get things just right, but it is pretty cool as you can have heavier or lighter objects, as well as circular or polygon collision mask.

You’ll also need to give the behavior to the walls, you can set them as a “Static” object rather than Dynamic so they will just stay in place.

If you want the object to be really bouncy, set the Restitution closer to 1. Restitution of 1 means that it retains all momentum after a collision. (More than 1 means that it gains more speed after collision which will of course get out of control fast)

If we are talking about same object then read below if not then what is below is useless to you

Imagine you have two apples one in each of your hand
You put apples next to each other
I tell you to move apple away from apple
I do not say appleS i say apple
One single apple
Which apple will you move away?
And that is what engine is conflicting against right now

So far only method i found to solve this is

I check distance between same objects and i add random instant force to them for as long as the distance is below 6 pixels
And so i get this

2023-10-26_09_37_l5R6GGMcRs_GDevelop

Hi,

Can someone look at the small game project on Itch?

You can play what we have now on Itch below:

NOTE: You can download the game project on above Itch page at the bottom.

Little lost here so hope someone knows how to fix this, thanks!
Everything works as I want except the rebounding of Enemy objects.

Jesse Lee

I tried to download it but it doesn’t contain a .json file?

Hi,

I chose “Save As” and chose “Your Computer”, then compressed the folder.
Did I do it wrong? I don’t see any other options for saving the project locally?

Jesse Lee

Hi,

I had a corrupted project, so I started from the beginning.

You can now properly download the project below:

Just want the Enemy balls to bounce off of all other Enemy balls when there is a collision.

Thanks!

Jesse Lee