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 - implementing throttle control

We already have rudimentary throttle control, in that we can set the throttle to maximum forward or maximum reverse, but we need finer control than that for our game. We'll create a new method for this:

  1. Just below the end of the cycleControl() method, add a new method that looks like the following code:
    def adjustThrottle(self, dir, dt):
    if(dir == "up"):
    self.throttle += .25 * dt
    if(self.throttle > 1 ): self.throttle = 1
    else:
    self.throttle -= .25 * dt
    if(self.throttle < -1 ): self.throttle = -1
    
  2. Next, we can simply delete these lines from the cycleControl() method:
    else:
    self.throttle = 0
    
  3. Now we need to change the lines where we set our throttle to use the new adjustThrottle() method. Change the line ...

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