We're going to modify our two tasks to take advantage of some of these other task return options. To start with, we're going to change cycleMove
so that it stops after the cycle has moved a set distance. After that, we'll change debugTask
to only print once every second.
The first thing to do is create a variable that will store the distance the cycle has travelled, so we can make it stop once that distance is greater than a certain amount. In our
__init__
method, we need to add a line to declare the variable. Put this line just before our call totaskMgr.doMethodLater
in the__init__
method.self.cycle2.setPos(-2,15,0) self.distTrav = 0
taskMgr.doMethodLater(5, self.cycleMove, "Cycle Move")
Now we need to increment that variable, and tell the task to stop afterself.distTrav
increases past a value. Add this block of code tocycleMove,
above the return statement we currently have.self.distTrav += 10 * dt if(self.distTrav >...