Hi there,
I made a dungeon crawler/maze runner. In the maze is a ghost. If he catches you, you get beamed back to the start. But after getting beamed to the start, the move velocity changes. Before everything is fine the character walks like he should. But after getting caught, the player moves the distance where he would need 2 to 3 secondes for with one tip of the key.
Code used to beam the character back to the beginning(100% the same function like the character is positioned for the first time!):
self.ownNode.setPos(-self.offset/2,-(self.offset/2)-self.entrance*self.offset,-1)
self.ownNode.setHpr(-90,-6.95,0)
Code to move the player forward:
z_pos=self.ownNode.getPos().get_z()
self.ownNode.setPos(self.ownNode,0, self.moveVelocity * dt,0)
self.ownNode.setPos(self.ownNode.getPos().get_x(),self.ownNode.getPos().get_y(),z_pos)
Debugging already showed that dt and self.moveVelocity do not change.
self.moveVelocity is set only outside of the functions at the beginning of the class:
moveVelocity=7.5
Also after getting caught the hud freezes and winning is not possible anymore I don’t understand why.
The part of the code of the ghost catching the player:
#got anybody??? collision
self.catchcTrav.traverse(render)
entries = list(self.catchHandler.getEntries())
alreadycaught=False
for caught in entries:
if re.match("player\d",caught.getIntoNode().getName()):
if not alreadycaught:
alreadycaught=True
self.actor.stop(self.actor.getCurrentAnim())
self.actor.play('catch')
self.status="catch"
number=int(re.search('\d',caught.getIntoNode().getName()).group(0))
self.playerCaught.append(number)
self.caughtdisabled=False;
taskMgr.doMethodLater(0.1,self.catchTask,'ghosteating')
if alreadycaught:
return task.done
Here is the task moving the players back to the beginning:
def catchTask(self,task):
if not self.caughtdisabled:
for i in self.playerCaught:
self.base.players[i-1].disableControls()
self.caughtdisabled=True;
catchcontrol=self.actor.getAnimControl('catch')
if catchcontrol.isPlaying():
#got anybody??? collision
self.catchcTrav.traverse(render)
entries = list(self.catchHandler.getEntries())
for caught in entries:
if re.match("player\d",caught.getIntoNode().getName()):
number=int(re.search('\d',caught.getIntoNode().getName()).group(0))
self.playerCaught.append(number)
self.base.players[number-1].disableControls()
return task.cont
else:
#animation done, move back to the beginning and reenable controls
for i in self.playerCaught:
self.base.players[i-1].setStart()
self.base.players[i-1].enableControls()
#remove ghost
self.getAway()
PS: How to enable proper indentation when posting here? # Thanks serega-kkz