A game loop

Ok this is more of a Python problem than a Panda problem but I hope I can get some help.

I want to make some kind of main loop usually in C++ you could use

while(1)
{

}

But we aint in Cansas anymore and I really don’t know how to use Python, how can I do this?

Thanks

Paul

in python you would usually do:

while 1:

but panda doesnt seem to like while loops, so you’ll have to setup a task ie:



def __init__(self):
        taskMgr.add(self.cameraLoop,'cameraFollowTask')

def cameraLoop(self,task):
        # this task makes the camera follow the player in 3rd person view
        speed = 6.0 # ft/s
        offset = Vec3(0,15,7)
        dt = globalClock.getDt()
        
        currPos = camera.getPos()
        desiredPos = self.player.getPos()+self.player.getQuat().xform(offset)
        direction = Vec3(desiredPos-currPos)
        if (direction.length()>speed*dt):
            direction.normalize()
            camera.setPos(camera.getPos()+direction*speed*dt)
        else:
            camera.setPos(desiredPos)
        
        camera.lookAt(self.player,Point3(0,0,4))

        # return Task.cont if you want the task to keep running
        # if it should only run once, dont return it.
        return Task.cont

You can find more (and better) info on tasks in the manual.

Good luck!

Ahh that makes sense now I had done a task example from the documentation but it didn’t sink in.

Thanks for your prompt response.