A weapon that can't hit anything isn't much good to us. In order to hit things, we need to use collision detection. Let's go ahead and add collision detection to our MachineGun
class so we can shoot some things in the scene.
Before we start going hog wild with this, let's create a small explosion effect to use when the laser strikes something. Open a new file and save it as
ExplosionClasses_01.py
.Place these imports at the top of the file:
from direct.interval.IntervalGlobal import * import random
Add the class definition and the
__init__
method as follows:class Pop: def __init__(self, pos): rand = random.randint(1,3) self.pop = loader.loadModel( "../Models/Explosions/Laserburst" + str(rand) + ".bam") self.pop.reparentTo(render) self.pop.setPos(pos) self.pop.find('**/+SequenceNode').node().play(0, 15) self.self = self self.seq = Sequence( Wait(.5), Func(self.destroy))
Now, we just...