A simple camera controller for the Panda3D engine.
It allows you to move with ZQDS (that's because I'm French ;D) keys and to look around or move with the mouse.
You can easily change the default keys in order to setup a WASD configuration (How to just after the "Example of use" section).
from direct.showbase.ShowBase import ShowBase
from camera import CameraControllerBehaviour
class MyApp(ShowBase):
def __init__(self):
super.__init__()
# Load a model
cube = self.loader.loadModel("models/box.egg")
cube.reparentTo(self.render)
# Setting up the camera controller
cam_controller = CameraControllerBehaviour(self.camera) # Apply the behaviour to the showbase camera object
cam_controller.setVelocity(0.2)
cam_controller.setMouseSensivity(0.1)
cam_controller.setup()
if __name__ in '__main__':
MyApp().run()
In order to change the default keyboard controls to a WASD confguration, you need to pass this dictionary inside the setup method of the controller :
cam_controller.setup(keys={
'w':"forward",
's':"backward",
'a':"left",
'd':"right",
'space':"up",
'lshift':"down"
})
Note: You can put whatever key you want as long as they are supported by Panda3D (see Keyboard Support for more information).