I have two models:
- Player (Lara) model which I define in init(self) of the Class World as follows:
laraStartPos = self.environ.getPos()
self.loadEnvironment()
self.lara = Actor("models/larawalkgun",
{"run":"models/larawalkfire",
"walk":"models/larawalkfire",
"fire":"models/laragunfire"})
self.lara.reparentTo(render)
self.lara.setScale(.03)
self.lara.setPos(laraStartPos)
- The model Pole is defined as follows:
self.pole1 = Actor("models/pole")
self.pole1.reparentTo(render)
self.pole1.setTag("Pole1","1")
self.pole1.setScale(0.03)
self.pole1.setPos(0,-13,-1.2)
I want to attach a Collision Ray to the Pole, where the Ray will act as a ‘laser’. The Ray must be in an off/on mode and if the player touch it. its health (self.health) decreases. How do I attach the Collision Ray? And do I put it as a task?
Secondly, for the player I have a task which caters for the key press actions and when I press ‘f’ I want a Collision Ray to go in the direction of the pole. The code for the ‘fire’ part is as follows:
if (self.keyMap["fire"]!=0):
self.isShooting = True
self.lara.play("fire")
self.laraFire.play()
self.lara_ammo=self.lara_ammo-1
Is it possible to attach a Ray when I press on ‘f’ and then check for collisions with the pole? How do I do it?
What I’ve got for the Collision Ray is the following existing code in Ralph, which have been modified:
self.laraGroundRay = CollisionRay()
self.laraGroundRay.setOrigin(0,0,1000)
self.laraGroundRay.setDirection(0,0,-1)
self.laraGroundCol = CollisionNode('laraRay')
self.laraGroundCol.addSolid(self.laraGroundRay)
self.laraGroundCol.setFromCollideMask(BitMask32.bit(0))
self.laraGroundCol.setIntoCollideMask(BitMask32.allOff())
self.laraGroundColNp = self.lara.attachNewNode(self.laraGroundCol)
self.laraGroundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.laraGroundColNp, self.laraGroundHandler)