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 turning

Going only in straight lines is no fun. We can't have a racing game without turning so we need to get that put in as well.

  1. First, we want to add a new variable. Place the following code just below the line where we create the self.accel variable:
    self.handling = 20
    
  2. Next, we're going to write another method for turning. Add the following code just below the end of the cycleControl() method:
    def turn(self, dir, dt):
    turnRate = self.handling * (2 -
    (self.speed / self.maxSpeed))
    if(dir == "r"): turnRate = -turnRate
    self.cycle.setH(self.cycle, turnRate * dt)
    
  3. Finally, add the following code above the line in the cycleControl() method that calls self.speedCheck(dt) to put the new method to use:
    if(self.keyMap["d"] ...

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