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()
When moving the player it bounces usually off the walls, but sometimes it passes into or through the walls
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