Ok, nevermind. I solved this question. I used the method listed by @Hollower here:
For who may interest:
from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor
app = ShowBase()
app.disableMouse()
app.acceptOnce("mouse3", app.enableMouse)
environ = loader.loadModel("environment")
environ.reparentTo(render)
panda = Actor("panda")
panda.reparentTo(render)
panda.setPos(40,-150,3)
pandaInterval = panda.hprInterval(5, (360,0,0), (0,0,0))
pandaInterval.loop()
bullets = []
bulletSpeed = 50.0
bulletLife = 5.0 # seconds bullet will remain in the scene
class Bullet(object):
# model is left unparented because it will be copied
model = loader.loadModel("smiley")
def __init__(self, pos, hpr, speed, life):
self.node = Bullet.model.copyTo(render)
self.node.setPosHpr(pos, hpr)
self.speed = speed
self.life = life
self.alive = True
def update(self, dt):
if not self.alive:
return
self.life -= dt
if self.life > 0:
# You should use the "fluid" versions of these functions
# if you intend them to work with the collision system.
self.node.setFluidY(self.node, self.speed * dt)
else:
self.node.removeNode()
self.alive = False
# Every frame this task calls update on each bullet in the bullets list.
def updateBullets(task):
dt = globalClock.getDt()
for bullet in bullets:
bullet.update(dt)
return task.cont
def shoot():
global bullets
bullets = [b for b in bullets if b.alive] # remove any dead bullets
bullets.append( Bullet(app.camera.getPos(), app.camera.getHpr(), bulletSpeed, bulletLife) )
app.accept("space", shoot)
taskMgr.add(updateBullets, "updateBullets")
app.camera.setPos(40,-250,70)
app.camera.lookAt(panda)
app.run()
Very important: bullet speed must be positive (different from original code which is negative).