Physics Collisions and how it fails sometimes. [Urgent]

Hey Gamers , 

There is a Semi circle shape which is drawn by CodenWeb physics editor. On detecting the collision with a bullet. It some times goes through the semi circle. 

And more over the Bullet Collision (Circular Bullet) should be detected when it hits the semicircle at edges. 

​Case 1: What I See is , In Some cases the bullet is detected at its edge.

Case 2: In some case The Bullet partially penetrates the Semi circle and then collision is detected.

Case 3 : And in very rare cases, Bullets completely penetrates the semi circles. 

which I Think is not a expected behavior. 

PLEASE HELP 

This is a common problem - try searching the forums and documentation first. Check here, for example:

https://forums.coronalabs.com/topic/63798-fast-moving-object-collision-detection-problem/?p=331071

We are using physics editor , Does that convert vertices in clockwise manner? I Think that’s also important?

Still struggling with the problem. 

What We did is , Reduced the speed of bullet. The Issue seems to be fixed. This seems to be limitation of corona. 

The problem is that the semi-circle is thin. The ball directly jumps to the other side of the circle if it’s too fast.

Bullet mode should fix this - I think you have to set it on both objects. I have no idea why it does not work in your case… Bullet mode can be expensive since calculation is way more complex than using the simple collision resolver.

What you did also works: Limiting the speed. This makes sure that the ball touches the obstacle.

You can also adjust the simulation:

http://docs.coronalabs.com/api/library/physics/setTimeStep.html

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

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

To be clear.  This is NOT a limitation of Corona.  It is how Box2D and physics simulation works in general.

You’re assuming that collision detection is continuous, but in fact it is broken up into discrete bites for calculation.

Whereas you think of the path of a bullet like this:

______________________________________________________________>

In simulation (which is all physics engines do), it is really more like this:

_       _       _       _       _       _       _       _       _       _       _       _       _       _       >

The gaps above represent  places where tunneling can occur.  The dashes are points where collisions are checked over time.

See the tips that Andreas gave above for help with this, as well consider setting ‘isBullet’ flag on the MOVING object to true, AFTER you add a body to the object.  (Andreas refered to this as ‘Bullet Mode’)

Thanks for the resource , Will consider these as well.

Unfortunately limiting the speed doesn’t work(What we tried earlier). It has reduced the frequency but issues is still there. 

Please find the code below, When I increase the speed of the ball  transition.to( ball, { x=0, time=200 }  ) at time 600 it works fine. But when I reduce it to 200 , it penetrates the wall. can you please help.

local physics = require("physics") physics.start() physics.setGravity( 0, 0) local wall = display.newRect (20, 0,5, display.contentHeight); wall:setFillColor(255,255,255,255) wall.myName = "wall" physics.addBody(wall, "static") local ball = display.newCircle(display.contentWidth-20, display.contentHeight/2, 20) ball:setFillColor(255,255,255,255) ball.myNmae = "ball" ball:toFront() physics.addBody(ball, "dynamic", {radius = 28}) ball.isBullet = true local function touchevent ( event ) if event.phase == "began" then transition.to( ball, { x=0, time=200 } ) end end Runtime : addEventListener( "touch" , touchevent) local function onCollision(event) if event.phase == "began" then if event.other.myName == "wall" then transition.cancel(ball) end end end ball:addEventListener("collision", onCollision)

It is not a good idea to use transition.to on physics body. you should use

object:applyForce()

object:applyLinearImpulse()

object:setLinearVelocity()

This is a common problem - try searching the forums and documentation first. Check here, for example:

https://forums.coronalabs.com/topic/63798-fast-moving-object-collision-detection-problem/?p=331071

We are using physics editor , Does that convert vertices in clockwise manner? I Think that’s also important?

Still struggling with the problem. 

What We did is , Reduced the speed of bullet. The Issue seems to be fixed. This seems to be limitation of corona. 

The problem is that the semi-circle is thin. The ball directly jumps to the other side of the circle if it’s too fast.

Bullet mode should fix this - I think you have to set it on both objects. I have no idea why it does not work in your case… Bullet mode can be expensive since calculation is way more complex than using the simple collision resolver.

What you did also works: Limiting the speed. This makes sure that the ball touches the obstacle.

You can also adjust the simulation:

http://docs.coronalabs.com/api/library/physics/setTimeStep.html

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

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

To be clear.  This is NOT a limitation of Corona.  It is how Box2D and physics simulation works in general.

You’re assuming that collision detection is continuous, but in fact it is broken up into discrete bites for calculation.

Whereas you think of the path of a bullet like this:

______________________________________________________________>

In simulation (which is all physics engines do), it is really more like this:

_       _       _       _       _       _       _       _       _       _       _       _       _       _       >

The gaps above represent  places where tunneling can occur.  The dashes are points where collisions are checked over time.

See the tips that Andreas gave above for help with this, as well consider setting ‘isBullet’ flag on the MOVING object to true, AFTER you add a body to the object.  (Andreas refered to this as ‘Bullet Mode’)

Thanks for the resource , Will consider these as well.

Unfortunately limiting the speed doesn’t work(What we tried earlier). It has reduced the frequency but issues is still there. 

Please find the code below, When I increase the speed of the ball  transition.to( ball, { x=0, time=200 }  ) at time 600 it works fine. But when I reduce it to 200 , it penetrates the wall. can you please help.

local physics = require("physics") physics.start() physics.setGravity( 0, 0) local wall = display.newRect (20, 0,5, display.contentHeight); wall:setFillColor(255,255,255,255) wall.myName = "wall" physics.addBody(wall, "static") local ball = display.newCircle(display.contentWidth-20, display.contentHeight/2, 20) ball:setFillColor(255,255,255,255) ball.myNmae = "ball" ball:toFront() physics.addBody(ball, "dynamic", {radius = 28}) ball.isBullet = true local function touchevent ( event ) if event.phase == "began" then transition.to( ball, { x=0, time=200 } ) end end Runtime : addEventListener( "touch" , touchevent) local function onCollision(event) if event.phase == "began" then if event.other.myName == "wall" then transition.cancel(ball) end end end ball:addEventListener("collision", onCollision)

It is not a good idea to use transition.to on physics body. you should use

object:applyForce()

object:applyLinearImpulse()

object:setLinearVelocity()