Physics Bug With Static Object Overlaying Dynamic Object

So I’ve created a game and I’ve got almost all the bugs ironed out but one last one persists. I’ve had it the entire time and don’t know what I can do to get rid of it. To understand it you need to understand my game itself. Its a brick breaker game, but instead of a paddle you have a dragon that can be drawn anywhere. What this causes issues with is that the dragon can be drawn around and over the ball. This causes the physics engine to bog down hard trying to calculate where the ball should go. I’ve added this video as an example. 

https://youtu.be/MHsGPWIQH9Q

I think you’ll probably need to help the physics engine out, perhaps move the ball out of the way of the dragon and calculate the effect of the initial collision yourself.

That was my first instinct as well, I’ve thought of pausing the physics engine as well. However I’m really running into issues trying to detect the first problem. It’s difficult to detect if its normal gameplay or the bug happening. 

Make the components of the dragon sensors. When a collision occurs, calculate the angle the ball has with its nearest dragon component and use applyForce() or applyLinearImpulse() to push it away.

Don’t forget to fire the force/impulse by using a timer - you can’t affect the physics world from within the handler of a collision event.

Cool looking game.

This is the exact brilliant response I am looking for! I’m still working on how to calculate the angle but this is the solution that should solve the physics problem. 

https://github.com/HoraceBury/MathLib

I case someone comes across this in the future. This solved the issue. 

A few notes: 

1.) Applying a force without a timer is now a possibility with Corona it seems like the physics was updated at sometime so there isn’t the need for a timer anymore, and with the timer it was causing issues. 

2.) I had to set a flag so that an additional counter force wouldn’t be applied until the collision had ended. I set these flags by using phase == began and phase == ended sections within the collision listener. 

3.) Figuring out which side the ball should come off the dragon took a little fancy math. I solved it by getting the two normal angles to the direction of the dragon and comparing balls angle to the physical distance between the ball angle and the two normal angles to figure out which angle was the closest. 

I’m not sure that your first point, i.e. the physics library being updated, was actually not done.

Corona uses Box2D and I don’t think it has been updated for almost a year. Not sure which version of it Corona is using either. I am also not aware of any problems with applying force to objects to begin with.

It is likely that you simply ran into some issues related to it, such as trying to apply force object to an object before it had actually been created by the physics engine, or maybe you were fighting the physics engine itself.

I might have been mistaken but I thought you used to be that you had use a timer when apply physics changes aka: 

Don’t forget to fire the force/impulse by using a timer - you can’t affect the physics world from within the handler of a collision event.

I could have been mistaken, either way you don’t need to use the timer to get it to work. 

I think you’ll probably need to help the physics engine out, perhaps move the ball out of the way of the dragon and calculate the effect of the initial collision yourself.

That was my first instinct as well, I’ve thought of pausing the physics engine as well. However I’m really running into issues trying to detect the first problem. It’s difficult to detect if its normal gameplay or the bug happening. 

Make the components of the dragon sensors. When a collision occurs, calculate the angle the ball has with its nearest dragon component and use applyForce() or applyLinearImpulse() to push it away.

Don’t forget to fire the force/impulse by using a timer - you can’t affect the physics world from within the handler of a collision event.

Cool looking game.

This is the exact brilliant response I am looking for! I’m still working on how to calculate the angle but this is the solution that should solve the physics problem. 

https://github.com/HoraceBury/MathLib

I case someone comes across this in the future. This solved the issue. 

A few notes: 

1.) Applying a force without a timer is now a possibility with Corona it seems like the physics was updated at sometime so there isn’t the need for a timer anymore, and with the timer it was causing issues. 

2.) I had to set a flag so that an additional counter force wouldn’t be applied until the collision had ended. I set these flags by using phase == began and phase == ended sections within the collision listener. 

3.) Figuring out which side the ball should come off the dragon took a little fancy math. I solved it by getting the two normal angles to the direction of the dragon and comparing balls angle to the physical distance between the ball angle and the two normal angles to figure out which angle was the closest. 

I’m not sure that your first point, i.e. the physics library being updated, was actually not done.

Corona uses Box2D and I don’t think it has been updated for almost a year. Not sure which version of it Corona is using either. I am also not aware of any problems with applying force to objects to begin with.

It is likely that you simply ran into some issues related to it, such as trying to apply force object to an object before it had actually been created by the physics engine, or maybe you were fighting the physics engine itself.

I might have been mistaken but I thought you used to be that you had use a timer when apply physics changes aka: 

Don’t forget to fire the force/impulse by using a timer - you can’t affect the physics world from within the handler of a collision event.

I could have been mistaken, either way you don’t need to use the timer to get it to work.