O'Reilly logo

Panda3D 1.6 Game Engine by Dave Mathews

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - adding collision detection to the MachineGun

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.

  1. 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.
  2. Place these imports at the top of the file:
    from direct.interval.IntervalGlobal import *
    import random
    
  3. 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" + ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required