[Physics] Objects passing through each other at high speeds

Hello,
the other day I downloaded the Pinball Madness example from Ansca(http://developer.anscamobile.com/code/pinball-madness)
I picked the code apart until I understood most of it. I’m new to Corona and this was always a good learning method for me.

The problem:
In the example project, physics are very unreliable. (To the point of being broken, when it comes to a pinball game) The ball passes through the flipper paddles, the spring shoots through the ball and I even got the ball stuck in the paddles a good few times. I tried around with this for days now and can’t get it to work properly. As I’m new, I know I’m probably doing something wrong.

If somebody could help me fix this, I would VERY VERY happy since this is bugging me a lot.

Here is what I tried already:

1.)Tried out PositionIterations and VelocityIterations, trying out different values. Didn’t change much it seems, even extremely high numbers didn’t prevent it from happening.
2.)Changed ball size/radius
3.)Redoing the collision shapes for the paddles, from complex to simple rectangles
4.)Added isBullet to both the ball and the paddles (Might have been at the wrong place, but I tried a bunch of different locations to add it)
5.)Changed densitiy of both the ball and the flippers, didn’t get rid of the problem, except that it seems to happen more often with low density
6.)Searched for similar problems in the forums and read the threads on the subject
7.)Read the post by Jonathan Beebe that got recommended in one of those threads (http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/)
8.)Tried to reduce the speed of the ball through less bounce and more friction
9.)Increase the FPS setting in the config.lua to 60
10.)Tried physics.setScale(60) (working with an iPad)

I hope somebody can help.

Thanks in advance.

John [import]uid: 65258 topic_id: 16297 reply_id: 316297[/import]

@kunio, I’ve gone through exactly the same process you’ve described above, and I still don’t have real solution to super fast moving physics bodies passing through where they shouldn’t. If there are a solution or two (besides all 10 listed above), I’d like to know it too. [import]uid: 67217 topic_id: 16297 reply_id: 60695[/import]

I thought I could maybe limit the speed or something, I don’t know if that would be preventing it, or would be a worthy trade off.

Does this mean it’s pretty much unusable for a pinball game, or something similar where it’s important the collisions are precise? [import]uid: 65258 topic_id: 16297 reply_id: 60701[/import]

I wouldn’t say “unusable” – it depends on how it is incorporated into a particular game, and whether or not, it causes true damage to the game experience you are trying to create. I haven’t looked at pinball game sample, but if you are unhappy with the pinball game experience offered in the sample game, then perhaps, in your opinion, it isn’t the right fit for pinball game. [import]uid: 67217 topic_id: 16297 reply_id: 60711[/import]

That’s why I’m asking how I could fix it. I know it’s possible because I’ve seen it working, but I have no clue what I’m doing wrong. [import]uid: 65258 topic_id: 16297 reply_id: 60728[/import]

Let’s hope someone will jump in and let us know how to solve it. I would very much like to have every supposed-to-be-solid object stay like a stone-solid object after all. [import]uid: 67217 topic_id: 16297 reply_id: 60729[/import]

that’s an issue with Box2D implementation in Corona, I was reading somewhere that Box2D can set the world units in Meters for more accuracy, but in Corona it is set in Pixels, so it kind of gets fuzzy at times and *misbehaves*

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16297 reply_id: 60753[/import]

Is there any workaround I could do? Especially for a Pinball scenario? I’d love to get this working somehow.

Edit: How could I limit the balls speed? Maybe I can get a limit to work that is high enough to not feel bad but low enough to not let the ball go crazy.

edit2: It also happens when the ball is slow and I flip one of the paddles. Sometimes it goes right through the ball even though the ball is barely moving. [import]uid: 65258 topic_id: 16297 reply_id: 60756[/import]

@kunio, about what you mentioned in your edit2, does this happen in the sample code supplied by Ansca? If it doesn’t, then there could be something wrong with your code. But if it does, then it’s the issue with Box2D implementation that Jayant mentioned above, for which Ansca didn’t have a work around to use in the sample. [import]uid: 67217 topic_id: 16297 reply_id: 60856[/import]

Yes it does happen, even more frequently. In general the example doesn’t seem to be very well taken care of. None of the measures I detailed in my first post are in, except “isBullet”, some comments refer to the ball as fruit, the function of “tap right to flip right, tap left to flip left” that is mentioned in the code isn’t in etc. With the stuff I’ve posted above I got it to work better than the Ansca example, only that still every once in a while the paddle flips through the ball, which really breaks the gameplay experience.

[import]uid: 65258 topic_id: 16297 reply_id: 60860[/import]

If you’ve made improvements on the example, please share them via the Code Exchange or github, so they can be improved on even more. [import]uid: 49447 topic_id: 16297 reply_id: 60885[/import]

I am not sure if this is helpful because I have not tested any of it out, and I have no idea what I am doing yet… but I was playing with the gravity/bounce in the Breakout sample code at http://www.youtube.com/watch?v=4ee261iYTaI

I got that ball moving pretty fast and I never went though the paddle or the walls. You should grab the code from that and see if you can recreate the ball though walls thing with it or see if it is doing something different. My guess without looking at anything is static objects. [import]uid: 95498 topic_id: 16297 reply_id: 60957[/import]

What could I do to limit the speed of the ball? I already tuned the friction, but what would I have to put to prevent it from going over X speed? Or rather, which values to address?
Edit: Doublepost, This was supposed to be an edit. [import]uid: 65258 topic_id: 16297 reply_id: 60994[/import]

I’ve got the sample problem. I tried the same things as you did but no solution. I think this is a bug and nobody cares about it… Look at the DragPlatforms example. It’s a joke. You can easily drag any objects through others.
There is only one thing that I could figure it out. This bug depends on the paddle’s rotation speed not the ball speed. I used joints(pivot) so I connected the paddle to a static background element. If I set the motor speed around 400, the ball never went through the paddle. But It’s unrealistic and unplayable this way. If I set the motor speed to 800 the ball of course went through the paddle.
All the code examples that I found here have the same problem. So I gave up. I think all I can do is waiting for a fix. [import]uid: 13852 topic_id: 16297 reply_id: 61415[/import]

Thanks, I’ll take a look at that and see if that helps.

Edit: it doesn’t. [import]uid: 65258 topic_id: 16297 reply_id: 60968[/import]

I tried that too already. As you said, way too slow. And not only that, but even then the ball passes through occasionally. (Still way too much to ignore the problem.) a nd yeah, the ball often passes through when it isn’t even that fast, and just at a steady speed. If you flip the paddle then, whoosh, ball flies right through.

This is really quite nasty and a big problem for a lot of physics games. Who from Ansca can I (or better: could we) mail about this so this gets acknowledged and fixed? [import]uid: 65258 topic_id: 16297 reply_id: 61469[/import]

I don’t know I’m just going to report it.(there’s a link at the top of this page. ‘Report a bug’) I’m afraid they’ll say that this is a Box2D bug not a Corona one. (it can be) I don’t know which Box 2D version is in Corona. I hope it’s not 2.2.0 because that’s the latest and has lots of bug fixes according to the Box 2D website.
I’m sure I’m not going to be a subscriber until they fix this issue. [import]uid: 13852 topic_id: 16297 reply_id: 61516[/import]

Check out what JayantV wrote above:
that’s an issue with Box2D implementation in Corona, I was reading somewhere that Box2D can set the world units in Meters for more accuracy, but in Corona it is set in Pixels, so it kind of gets fuzzy at times and *misbehaves
So I’m hopeful it is on fact a problem in corna, and not in box2D. [import]uid: 65258 topic_id: 16297 reply_id: 61542[/import]

I too have had these problems. What you can try is applying linear impulses to negate the effects of balls going through walls.

In my game it uses a…special way of controlling the environment that is very quick. I had to write some collision detection, and then apply impulses on impact to keep it from going through an object.
I’m not at a spot where I have the code, but I had to do some weird crazy ass manipulation and path finding to get things to work.

Basically it cooked up something like this
Wrote a function for collision detection that freezes the object for a millisecond by changing the object from dynamic to static, then capturing the previous velocity of the object and passing that as a parameter into applying linear impulse.
So when the ball is traveling, you will have to capture the velocity, and store it then retrieve that and translate that into an impulse that will travel at an equivalent angle.

Keep in mind, I never coded anything before june 2011, so that above took me a very very long time to even get better results.

Basically, you are looking at getting angles, and recording them, along with velocities and everything else. Once the ball goes static, then back to dynamic you need all that information to get realistic trajectories. My game isn’t a paddle ball game, so the ever so slight delay may not be desired.

Box2d manual was my friend - but I realized the things I wanted to do, and what it can do are 2 different things so thus I had to be stupidly creative and re purpose other API’s to get things working decently lol.
Yea, welcome to the pass through paradise problem :slight_smile:
ng [import]uid: 61600 topic_id: 16297 reply_id: 61786[/import]

Thanks for the lengthy reply. I don’t think a delay would be acceptable in what I’m trying to do, nor do I think that I’d be able to come up with a workaround quite as complex as yours, as I said, I’m pretty new to this all.

I received an email that the post from Ansca’s Pinball example was updated, however the code of the example is still the same, and the text in the post seems to be unchanged too, so not sure what the update was about.

Not sure if I can submit a bug report, because in the bug base it says only subscribers can view and contribute bugs. [import]uid: 65258 topic_id: 16297 reply_id: 61943[/import]