Collision Detection problems: Sphere passes through wall

Hi,

I am making my first game with Panda3D, it is a top down 2D shooter. My level consists of quads and each quad has a CollisionBox attached for collision detection. The player’s ship has a CollisionSphere attached:

self.collisionHandler = CollisionHandlerQueue()

self.ship = render.attachNewNode("ship")
self.ship.setTwoSided(True)
self.shipHeading = Vec3(0, 0, 0)
shipObject = loadObject("plane", "ship2", self.ship, depth=PlayerHeight, transparency=True)
self.setVelocity(self.ship, Vec3(0, 0, 0))
shipCollider = self.ship.attachNewNode(CollisionNode("player ship"))
        
shipCollider.node().addSolid(CollisionSphere(0,0,0, 1.0))
shipCollider.show()
self.collisionTraverser.addCollider(shipCollider, self.collisionHandler)

and

# tile is a NodePath
tileCollider = tile.attachNewNode(CollisionNode("wall (%i, %i)" % (x,y)))
tileCollider.node().addSolid(CollisionBox(Point3(0,0,0), 0.5, 0.5, 0.5))
tileCollider.show()

The result looks like this:

When moving the player it bounces usually off the walls, but sometimes it passes into or through the walls :frowning:

My collision handler, first method to respond to a collision:

traveledWay = self.getVelocity(self.ship)*dt
self.ship.setPos(self.ship.getPos() + traveledWay*-1.5)

The second one I tried:

self.setVelocity(self.ship, self.getVelocity(self.ship) * -1.0)

And the third one I took from the “Ball in Maze” sample:

reflectionVector = (normal * normal.dot(inVector * -1.0) * 2.0) + inVector

self.setVelocity(self.ship, reflectionVector * (currentSpeed * (((1-velocityAngle)*0.5)+0.5)))

disp = entry.getSurfacePoint(self.render) - entry.getInteriorPoint(self.render)
newPosition = self.ship.getPos() + disp
self.ship.setPos(newPosition)

All three methods show some problems, that sometimes the CollisionSphere passes through the walls.

Do you have any idea or suggestions what else I could try or what is wrong with my code?

Thank you,
Enrico

Have you considered using a CollisionHandlerPusher instead of doing the work yourself? The advantage to this is that the pusher already includes the (fairly complicated) logic to ensure that collisions work reliably 98% percent of the time.

David

I tried the demo from the manual with that Pusher and I am able to penetrate the static sphere in the demo deeply. So I decided against it. I will try again now :slight_smile:

I integrated the CollisionHandlerPusher and it is way better now :slight_smile:
However, with some trying the sphere can still pass through the boxes :frowning:

Edit: My ship is slowly moving, 5 units per second max. I am currently implementing the suggestions from: panda3d.org/manual/index.php/R … ng_Objects

Any more ideas?

No collision system can be perfect, but it should work the vast majority of the time. I’m not sure about boxes, though–the fact that they have two back-to-back faces (which might be closer together than the radius of your sphere) could be causing problems. Try using just one-sided CollisionPolygons, or making your boxes larger than your sphere.

David