PandaFPS (Simple FPS Controller for Panda3D)

I made a simple FPS controller for Panda3D. Check it out!

An interesting approach is to return return task.cont in each code of if block. I wonder what inspired this decision?

And what a feature that only supports Windows OS, it sounds like nonsense.

My example that works so far, with minor edits for Python 3.

1 Like

So apparently the windows size checking feature requires a Windows library (from what I see in the terminal). I will run this is Linux though and see if that command triggers different checks on Windows and Linux.

For the Task.cont I added this for the mouse pointer lock feature which I will eventually add. I just wanted to make sure mouse coordinates were being updated each frame.

The main problem that I see with the use of “Task.cont” as you currently have it is that, if I’m reading this correctly, it will prevent the user from using more than one movement key at once, and thus limit how the user can move.

For example, if the user is holding down “w” in order to move forward and “a” in order to move left, they’ll only move forward, rather than diagonally forward-and-left.

I will try it removing task.cont (thanks for the suggestion). But my main question is that doesn’t “task.cont” tell the Panda3D task manager to repeat the step every frame? And if so, isn’t that what I need?

1 Like

Also, since I believe “task.cont” is still needed for the script to be executed each frame, should I just put “task.cont” at the bottom of each of my loops?

The main problem is less that you’re telling the task to continue (which is fine), but that you’re returning. When you “return” from a method, you exit it immediately, and thus nothing in the method that follows that “return” is executed.

So it’s a good idea to return “Task.cont”–but not to do so where you currently have it.

I think that what you suggested in your most-recent post–if I’m reading that correctly–is about right. That is, I’d suggest instead just having the return-statement occur near the end of the method, or at any other point at which you want the method to end. (For one thing, your return-statement after checking “dt > .20” can stay.)

(Although I’m a little confused by your mention of “loops”, plural–I only see the one task, so I’m not sure of where else you have in mind to put it?)

Something like this:

def cameraControl(self, task):
		dt = globalClock.getDt()
		if(dt > .20):
			# Exit the method here when the dt is too high,
			# doing nothing more.
			return task.cont

		# All your other code here ...

		# And finally:
		return task.cont

If I may, would you be interested in a few other points that I noticed in your code? They’re nothing that currently affects its functioning (as the “Task.cont” issue does), but they may be useful to learn. (And one of them has the potential to trip you up later, albeit that it’s a fairly unlikely event.)

Ok thank you so much I will implement this!

1 Like