Ask here your questions to get help using GDevelop.
By en4cer1133
#68350 Hello all again!

I am trying to make an asteroids game, and I have the ship and asteroids (mostly) behaving how I want to. The ship rotates with keypress and moves in the direction it is facing and then if the key is lifted, it keeps going in the direction to mimic a weightless environment. The asteroids drift and rotate independently. Here is where things start to get kind of complicated. I have been messing around with it for the past week, and have not made any progress. What I am trying to achieve: I have an event that envelops the ship in a shield to protect it from asteroid collision. I would like the asteroids to bounce off said shield and be redirected the opposite direction. Here is what I have tried so far:

If I use the physics engine for the asteroids and shield it seems to work ok and at least prevent the asteroids from hitting the ship and thereby destroying it. The asteroids don't get redirected. They just seem to fall around the ship and keep going in the direction they are "drifting".

I also tried things without the physics engine and it seems spotty at best. I have events set up that if the shield and asteroids collide, to stop the asteroid, and apply a force opposite from what is currently acting on it. (Got this idea from the breakout sample that is included. The behavior of the ball is similar to what I want of the asteroids only on a slower scale.) The stop command doesn't seem to work. I call that at the top of the action list, then add an opposite force
using the current force direction of the object as a variable and multiplying by -1. The asteroids don't seem to have the forces reset and redirected. They also seem to ignore the collision if they are rotating and go right through the shield and destroy the ship. I have tried pixel perfect collision detection and it still doesn't do what I want.

What would be the best way to achieve the goal I have listed above? Am I doing something wrong or is this just not possible? Ideally the asteroids would behave as they are in a weightless environment and bounce off one another and the shield of the ship. I would like the collisions to redirect the force made to simulate them "drifting" though the void.

Thanks in advance for any help you may be able to provide.