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 - tying the camera to the cycle

It's difficult to move the cycle when the camera doesn't go with it, so we're going to make the camera move with the cycle and while we're at it we can set up some zoom in and zoom out controls using the mouse buttons.

  1. For starters, we'll disable the default camera controls. Add this code just below our variable declarations in the __init__ method.
    base.disableMouse()
    
  2. After that, put this code into the __init__ method right below the line that calls self.cycle.setPos.
    base.camera.reparentTo(self.cycle)
    base.camera.setY(base.camera, -5)
    
  3. Now, we need to expand our key map to include the left and right mouse buttons. Change the key map definition to the following:
    self.keyMap = {"w" : False, "s" : False, ...

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