I have a lot of Asteroids in my space shooter game that are heading towards the player. After filling the screen with them I suddenly realized that it would be cooler if they bounce from each other based on their size, force etc.
So for starters I want to make it so that when an Asteroid collides with another one, each one goes to the opposite direction.
Any easy solutions? It seems that Gdevelop’s collision system can’t recognize two instances as different entities if they belong to the same object
One way is to have a second hidden object, say called “collider”, with the same collision mask as the asteroid. Stick a collider object to each asteroid object. Then check for collision between collider and asteroid objects (with the additional condition that the collider is not stuck to the asteroid) and separate the two objects.
If you use physics then you don’t need to worry about collision between object of the same type - the physics engine will work that out for you.
However, don’t mix physics behaviour and standard movement/collisions. It’ll lead to tears and frustration. Use one or the other, but not a combination to control the objects.
Hi, I replied to your first reply regarding the collider solution. I have no idea how to properly do it
Sadly I can’t use Psychics as they don’t fit my game.
imo i would approach the problem with the Id counter method.
Assigning an id for each meteor (so each meteor have unique id) and at collision do something with the bounce extension…
I’m telling this without even have tested it…so consider it just a probable input.
check for collision between an asteroid and collider that isn’t stuck to it. Counter to what I normally preach about using for each object, this is the only way I could make it work:
For now I have tried the Bounce extension. Literally just added the extension on the object and added an action that states that the asteroid should bounce away from each asteroid. I don’t know what kind of black sorcery the bounce extension is using but it works. Not perfect but it does the basic thing that I want.
Now because I want to calculate the force of the asteroid, cause I want some of them to get pushed back or get crushed by bigger ones I will try the collider option. Just wish there was a way to do it with the bounce extension.
One option for bouncing off each other is possibly adding an object var ‘force’ and object var ‘force x’ and ‘force y’. Give them unique id. Repeat for each. When colliding set the ‘force’ to a number based on size etc and the ‘force x’ ‘force y’ to the point of collission. In the repeat for each events. if ‘force’ greater than zero apply force ‘force’ in direction away from point force x, force y. and decrease ‘force’ by something like 100 to slow them down again