i have a ball in my game and i want to check whether my actor is colliding with it, then do something if he is colliding. the ball code is
self.ball = loader.loadModel(“models/ball”)
self.ball.reparentTo(render)
BallstartPos = Vec3(-109.961, 18.4281, -0.403214)#.getPos()
self.ball.setPos(BallstartPos)
self.ballSphere = self.ball.find("**/ball")
self.ballSphere.node().setFromCollideMask(BitMask32.bit(0))
self.ballSphere.node().setIntoCollideMask(BitMask32.allOff())
self.ball.setScale(2)
could anyone tell me an easy way to do this please?
rdb
July 6, 2007, 7:28am
2
There are multiple ways to do it. Which handler are you trying?
panda3d.org/manual/index.php/C … n_Handlers
my actor is handling collisions with the following code. im a complete noob. all i know is that im faking ground collision by casting a ray and then adjusting my Z coordinate if there is terrain in the spot im moving to.
self.cTrav = CollisionTraverser()
self.environ.setCollideMask(BitMask32.bit(1))
self.ralphGroundRay = CollisionRay()
self.ralphGroundRay.setOrigin(0,0,1000)
self.ralphGroundRay.setDirection(0,0,-1)
self.ralphGroundCol = CollisionNode('ralphRay')
self.ralphGroundCol.addSolid(self.ralphGroundRay)
self.ralphGroundCol.setFromCollideMask(BitMask32.bit(1))
self.ralphGroundCol.setIntoCollideMask(BitMask32.allOff())
self.ralphGroundColNp = self.ralph.attachNewNode (self.ralphGroundCol)
self.ralphGroundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)
self.camGroundRay = CollisionRay()
self.camGroundRay.setOrigin(0,0,1000)
self.camGroundRay.setDirection(0,0,-1)
self.camGroundCol = CollisionNode('camRay')
self.camGroundCol.addSolid(self.camGroundRay)
self.camGroundCol.setFromCollideMask(BitMask32.bit(1))
self.camGroundCol.setIntoCollideMask(BitMask32.allOff())
self.camGroundColNp = base.camera.attachNewNode(self.camGroundCol)
self.camGroundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.camGroundColNp, self.camGroundHandler)
rdb
July 6, 2007, 7:48am
4
You have to create a task, in that task, check the CollisionHandlerQueue for collision entries. You might want to read the manual section about that, or follow the Collision Detection or Roaming Ralph example in your Panda3D/samples directory.