Learn Panda3d - 10 Code Examples & CST Typing Practice Test
Panda3D is an open-source, cross-platform game engine primarily for Python and C++ that supports 3D rendering, physics, audio, input, networking, and VR/AR applications. It is designed for both educational and commercial projects, with a focus on rapid prototyping and full-featured 3D game development.
Learn PANDA3D with Real Code Examples
Updated Nov 24, 2025
Code Sample Descriptions
Panda3D Keyboard Movement Box
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Point3
class MoveBox(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.box = self.loader.loadModel('models/box')
self.box.reparentTo(self.render)
self.box.setPos(0, 10, 0)
self.pos = Point3(0, 10, 0)
self.accept('arrow_left', self.move, [-1])
self.accept('arrow_right', self.move, [1])
def move(self, x):
self.pos.x += x
self.box.setPos(self.pos)
app = MoveBox()
app.run()
Move a 3D box with arrow keys in Panda3D.
Panda3D Rotating Cube
from direct.showbase.ShowBase import ShowBase
class RotatingCube(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.cube = self.loader.loadModel('models/box')
self.cube.reparentTo(self.render)
self.cube.setPos(0, 10, 0)
self.taskMgr.add(self.rotate, 'rot')
def rotate(self, task):
self.cube.setH(self.cube.getH() + 1)
return task.cont
app = RotatingCube()
app.run()
Simple rotation of a cube using Panda3D task manager.
Panda3D Change Color on Click
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Vec4
import random
class ColorChanger(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.obj = self.loader.loadModel('models/panda')
self.obj.reparentTo(self.render)
self.obj.setPos(0, 20, 0)
self.accept('mouse1', self.change)
def change(self):
r = random.random()
g = random.random()
b = random.random()
self.obj.setColor(Vec4(r, g, b, 1))
app = ColorChanger()
app.run()
Click to change a model's color.
Panda3D Simple Jumping Object
from direct.showbase.ShowBase import ShowBase
class Jumper(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.cube = self.loader.loadModel('models/box')
self.cube.reparentTo(self.render)
self.cube.setPos(0, 15, 0)
self.accept('space', self.jump)
def jump(self):
self.cube.setZ(self.cube.getZ() + 1)
app = Jumper()
app.run()
Press space to make a cube jump.
Panda3D Mouse-Following Sprite
from direct.showbase.ShowBase import ShowBase
from direct.gui.OnscreenImage import OnscreenImage
class MouseFollow(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.cursor = OnscreenImage(image='cursor.png', pos=(0,0,0), scale=0.1)
self.taskMgr.add(self.update, 'follow')
def update(self, task):
if self.mouseWatcherNode.hasMouse():
x = self.mouseWatcherNode.getMouseX()
y = self.mouseWatcherNode.getMouseY()
self.cursor.setPos(x, 0, y)
return task.cont
app = MouseFollow()
app.run()
A 2D sprite follows the mouse position.
Panda3D 3D Camera Orbit
from direct.showbase.ShowBase import ShowBase
class CameraOrbit(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.model = self.loader.loadModel('models/box')
self.model.reparentTo(self.render)
self.model.setPos(0, 10, 0)
self.orbit = 0
self.taskMgr.add(self.rotateCam, 'orbit')
def rotateCam(self, task):
self.orbit += 0.5
self.camera.setPos(20, 20, 10)
self.camera.lookAt(self.model)
return task.cont
app = CameraOrbit()
app.run()
Right drag the mouse to orbit around a model.
Panda3D Toggle Visibility
from direct.showbase.ShowBase import ShowBase
class ToggleObject(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.model = self.loader.loadModel('models/panda')
self.model.reparentTo(self.render)
self.model.setPos(0, 15, 0)
self.visible = True
self.accept('v', self.toggle)
def toggle(self):
self.visible = not self.visible
self.model.show() if self.visible else self.model.hide()
app = ToggleObject()
app.run()
Press V to toggle the model's visibility.
Panda3D Spin On Key Hold
from direct.showbase.ShowBase import ShowBase
class SpinOnHold(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.obj = self.loader.loadModel('models/box')
self.obj.reparentTo(self.render)
self.obj.setPos(0, 15, 0)
self.taskMgr.add(self.spin, 'spin')
def spin(self, task):
if self.mouseWatcherNode.is_button_down('arrow_left'):
self.obj.setH(self.obj.getH() - 1)
if self.mouseWatcherNode.is_button_down('arrow_right'):
self.obj.setH(self.obj.getH() + 1)
return task.cont
app = SpinOnHold()
app.run()
Hold left/right arrows to spin a model.
Panda3D Resize Model
from direct.showbase.ShowBase import ShowBase
class ScaleModel(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.obj = self.loader.loadModel('models/box')
self.obj.reparentTo(self.render)
self.obj.setPos(0, 15, 0)
self.scale = 1
self.accept('+', self.change, [0.1])
self.accept('-', self.change, [-0.1])
def change(self, amt):
self.scale += amt
self.obj.setScale(self.scale)
app = ScaleModel()
app.run()
Press +/- to change model scale.
Panda3D Auto Forward Motion
from direct.showbase.ShowBase import ShowBase
class AutoMove(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.obj = self.loader.loadModel('models/box')
self.obj.reparentTo(self.render)
self.obj.setPos(0, 5, 0)
self.taskMgr.add(self.move, 'moveTask')
def move(self, task):
z = self.obj.getY()
self.obj.setY(z + 0.05)
return task.cont
app = AutoMove()
app.run()
Model automatically moves forward in 3D space.
Frequently Asked Questions about Panda3d
What is Panda3d?
Panda3D is an open-source, cross-platform game engine primarily for Python and C++ that supports 3D rendering, physics, audio, input, networking, and VR/AR applications. It is designed for both educational and commercial projects, with a focus on rapid prototyping and full-featured 3D game development.
What are the primary use cases for Panda3d?
3D games (desktop and mobile). Educational simulations and VR apps. Visualization tools and interactive media. Prototyping 3D environments. Research and AI simulation
What are the strengths of Panda3d?
Python-friendly, easy for rapid prototyping. Extensive 3D feature set. Open-source and free for commercial use. Highly customizable and flexible. Active community support and documentation
What are the limitations of Panda3d?
Not beginner-friendly for complex 3D projects. Mobile support is limited and requires workarounds. Editor tooling is minimal compared to Unity/Unreal. Performance tuning requires C++ knowledge. Fewer ready-made assets and marketplaces
How can I practice Panda3d typing speed?
CodeSpeedTest offers 10+ real Panda3d code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.