object passes through wall....

I have read some of the posts in this area and haven’t quite found the answer I need - unless I just don’t understand what I am reading (which may be the case).

I have an object that I move up and down the screen in between a top and bottom wall.  It usually bounces as expected, even if you hit the wall several times quickly. However, every so often, and I can’t seem to determine how, the object will pass through the wall.  This usually occurs when bouncing in very rapid succession against the wall.

I have tried putting two layers of wall objects, and even offset them so the object has to pass through them both - but it still will make through occasionally.  I also increased the bounce of the object and the wall and increased the density of the walls, without success.

I just wonder if I am missing something in my understanding about how the physics works. I am kind of thinking that the physics body of the object is overlapping the wall and so the subsequent movement of the object against the wall (the new collision) is not detectable.  If this is the case - I am at a loss at how to solve it.

Anybody seen similar behavior? Any suggestions?

Thanks all!

You could try setting the balls isBullet to true.  This increases how often the object is checked for collisions.

See the API guide for a better understanding.  https://docs.coronalabs.com/api/type/Body/isBullet.html

My understanding is that the physics in box2D is based upon frames, therefore if your object is moving to fast and would be beyond the wall by the next frame thats where the engine places your object. This can be generally be countered by using .isBullet = true. 

Hi @sonyayllc,

Both of the answers already provided are correct. An additional option is to adjust the position/velocity iteration settings for the physics engine as a whole, which can help improve collision detection with fast moving objects… however, it affects the entire physics engine which might be overkill, so using the “isBullet” method should be your first approach, followed by these methods if that doesn’t do the trick.

https://docs.coronalabs.com/api/library/physics/setPositionIterations.html

https://docs.coronalabs.com/api/library/physics/setVelocityIterations.html

Brent

Excellent!  Thank you all so much - this has been a real killer for me.

The .isBullet fixed the issue and revealed a new one.  I think I can control the new one, but I do have another question.

Do object:applyForce() or object:setLinerVelocity() automatically take precedence over (or override) physics?

Hi @sonyayllc,

The object:applyForce() and object:setLinerVelocity() commands are specifically related to physics, nothing else. First one gives a sudden directional “kick” to the object, second one sets it moving in a steady constant direction.

Brent

Ok, Roger that. Still have some kinks to work through I guess, but I am on track k again.

Thanks for the help!

You could try setting the balls isBullet to true.  This increases how often the object is checked for collisions.

See the API guide for a better understanding.  https://docs.coronalabs.com/api/type/Body/isBullet.html

My understanding is that the physics in box2D is based upon frames, therefore if your object is moving to fast and would be beyond the wall by the next frame thats where the engine places your object. This can be generally be countered by using .isBullet = true. 

Hi @sonyayllc,

Both of the answers already provided are correct. An additional option is to adjust the position/velocity iteration settings for the physics engine as a whole, which can help improve collision detection with fast moving objects… however, it affects the entire physics engine which might be overkill, so using the “isBullet” method should be your first approach, followed by these methods if that doesn’t do the trick.

https://docs.coronalabs.com/api/library/physics/setPositionIterations.html

https://docs.coronalabs.com/api/library/physics/setVelocityIterations.html

Brent

Excellent!  Thank you all so much - this has been a real killer for me.

The .isBullet fixed the issue and revealed a new one.  I think I can control the new one, but I do have another question.

Do object:applyForce() or object:setLinerVelocity() automatically take precedence over (or override) physics?

Hi @sonyayllc,

The object:applyForce() and object:setLinerVelocity() commands are specifically related to physics, nothing else. First one gives a sudden directional “kick” to the object, second one sets it moving in a steady constant direction.

Brent

Ok, Roger that. Still have some kinks to work through I guess, but I am on track k again.

Thanks for the help!