Dynamic Task Time Keyboard Input

Hello,

I’d like to implement dynamic simulation playback speed in Panda. Basically I’d like to update the delay time of a task when the user strikes the right (decrease delay) or left (increase delay) keys. UpdateVehicleTask is the task I’m trying to alter. Thanks in advance for any suggestions!

My Attempt:

KEYBOARD INPUTS

        def KeyBoardEvents(self):
            self.accept("arrow_right", self.SPEEDUP)
            self.accept("arrod_left", self.SLOWDOWN)

        def SPEEDUP(self):
            self.speed = self.speed/2
            taskMgr.remove("UpdateVehicleTask")
            taskMgr.doMethodLater(self.speed,UpdateVehicle,"UpdateVehicleTask",\
                              extraArgs=[self, p,r,ya,x,y,z], \
                              appendTask=True)

I think it’s possible to adjust the delayTime of a task without recreating it. You can do that by storing the result of taskMgr.add in a variable, eg.

self.task = taskMgr.add(...)

…and then changing the delay time using something like:

self.task.delayTime = self.speed

Note that this requires you to use Task.again and not Task.cont.

Alternatively, you could make your task framerate-independent by scaling the movement it generates by globalClock.getDt(). But this might be difficult or undesirable depending on your simulation. See the Roaming Ralph sample for an example of this.

Note that you misspelled arrow_left.

Thanks again! I’m going to have to list in you in a credits section…