The code below does not work to my expectations. I want it to walk north if the user presses the "w" key. The Actor, panda does show movement for the first time not completing the animation, it stops and never moves again. Am I using the engine wrongly? Or Should I use something else to fulfil my purpose?
from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor
from panda3d.core import Point3
from direct.interval.IntervalGlobal import*
class Window(ShowBase):
def __init__(self):
ShowBase.__init__(self)
def loadModels(self):
self.envir = loader.loadModel("models/environment")
self.envir.reparentTo(self.render)
self.envir.setY(1183.37)
self.envir.setHpr(0, 8, 0)
self.panda = Actor("models/panda-model", {"idle": "models/panda-model", "walk": "models/panda-walk4"})
self.pandaPosY = 502
self.pandaPosX = 0
self.pandaPosZ = -102.66
self.panda.setScale(0.05, 0.05, 0.05)
self.panda.setY(502)
self.panda.setZ(-102.66)
self.panda.setHpr(180, 0, 0)
self.accept("w", self.MoveForward)
self.panda.reparentTo(self.render)
def MoveForward(self):
pandaForwardWalk = self.panda.posInterval(2, Point3(self.pandaPosX, self.pandaPosY + 50, self.pandaPosZ), startPos = Point3(self.pandaPosX, self.pandaPosY, self.pandaPosZ))
self.panda.play("walk")
self.pandaForwardWalk = Sequence(pandaForwardWalk, name="pandaForwardWalk")
game = Window()
game.loadModels()
game.run()
To loop the animation continuously, use .loop() instead of .play(). To actually move the model, use either .set_pos(), or look up LerpIntervals: https://www.panda3d.org/manual/index.php/Lerp_Intervals