The camera is parented to the panda actor so it will follow it. But it just stays at the panda’s feet. I can’t get it to sit behind the panda. I tried setting its position and that didn’t work. Then I tried changing it in the task and that didn’t work. I’m confused I thought that children nodes were supposed to follow their parents relatively not exactly.
font=loader.loadFont("cmss12")
def addInstructions(pos,msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1), font=font,
pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)
def AddTitle(text):
return OnscreenText(text=text, style=1, fg=(1,1,1,1), font = font,
pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)
class MyApp(DirectObject):
def __init__(self):
self.keyMap = {"left":0, "right":0, "forward":0, "reverse":0, "turn-left":0, "turn-right":0}
base.win.setClearColor(Vec4(0,0,0,1))
# Post the instructions
self.title = AddTitle("Dominick's Test App")
self.inst1 = addInstructions(0.95, "[ESC]: Quit")
self.inst2 = addInstructions(0.90, "[Left Arrow]: Left")
self.inst3 = addInstructions(0.85, "[Right Arrow]: ight")
self.inst4 = addInstructions(0.80, "[Up Arrow]: Forward")
# Load the environment model.
self.environ = loader.loadModel("samples/Roaming-Ralph/models/world")
# Reparent the model to render.
self.environ.reparentTo(render)
self.environ.setPos(0, 0, 0)
# Load and transform the panda actor.
self.panda = Actor("models/panda-model",{"walk": "models/panda-walk4"})
self.panda.setScale(0.005, 0.005, 0.005)
self.panda.setPos(0, 0, .2)
self.panda.reparentTo(render)
self.accept('w', self.setKey, ["forward",1])
self.accept('w-up', self.setKey, ["forward",0])
self.accept('a', self.setKey, ["left",1])
self.accept('a-up', self.setKey, ["left",0])
self.accept('s', self.setKey, ["reverse",1])
self.accept('s-up', self.setKey, ["reverse",0])
self.accept('d', self.setKey, ["right",1])
self.accept('d-up', self.setKey, ["right",0])
taskMgr.add(self.move, "moveTask")
# Game state variables
self.isMoving = False
base.camera.reparentTo(self.panda)
base.camera.setPos(0,-10,10)
base.disableMouse()
#Records the state of the arrow keys
def setKey(self, key, value):
self.keyMap[key] = value
def move(self,task):
elapsed = globalClock.getDt()
if (self.keyMap["forward"]!=0):
self.panda.setY(self.panda, elapsed*20)
if (self.keyMap["reverse"]!=0):
self.panda.setY(self.panda, -(elapsed*20))
if (self.keyMap["left"]!=0):
self.panda.setX(self.panda, elapsed*20)
if (self.keyMap["right"]!=0):
self.panda.setX(self.panda, -(elapsed*20))
if (self.keyMap["forward"]!=0) or (self.keyMap["reverse"]!=0) or (self.keyMap["left"]!=0) or (self.keyMap["right"]!=0):
if self.isMoving is False:
self.panda.loop("walk")
self.isMoving = True
else:
if self.isMoving:
self.panda.stop()
self.isMoving = False
base.camera.setPos(0,-10,10)
base.camera.lookAt(self.panda)
return Task.cont
w=MyApp()
run()