def _process(self, dt): Impulse.Impulse._process(self, dt) me = self.nodePath chaser = self.chaser chaserPos = chaser.getPos(me) chaserPos.setZ(0) distance = self.VecType(chaserPos).length() self.lookAtNode.lookAt(chaser) relH = reduceAngle(self.lookAtNode.getH(me) + 180.0) epsilon = 0.005 rotSpeed = self.mover.getRotSpeed() if relH < -epsilon: vH = -rotSpeed elif relH > epsilon: vH = rotSpeed else: vH = 0 if abs(vH * dt) > abs(relH): vH = relH / dt if distance < self.maxDist and abs(relH) < self.moveAngle: vForward = self.mover.getFwdSpeed() else: vForward = 0 distanceLeft = self.maxDist - distance if distanceLeft > 0.0 and vForward * dt > distanceLeft: vForward = distanceLeft / dt self.vel.setY(vForward) self.rotVel.setX(vH) self.mover.addShove(self.vel) self.mover.addRotShove(self.rotVel)
def _process(self, dt): Impulse.Impulse._process(self, dt) me = self.nodePath target = self.target targetPos = target.getPos(me) x = targetPos[0] y = targetPos[1] distance = math.sqrt(x * x + y * y) self.lookAtNode.lookAt(target) relH = reduceAngle(self.lookAtNode.getH(me)) epsilon = 0.005 rotSpeed = self.mover.getRotSpeed() if relH < -epsilon: vH = -rotSpeed elif relH > epsilon: vH = rotSpeed else: vH = 0 if abs(vH * dt) > abs(relH): vH = relH / dt if distance > self.minDist and abs(relH) < self.moveAngle: vForward = self.mover.getFwdSpeed() else: vForward = 0 distanceLeft = distance - self.minDist if distance > self.minDist and vForward * dt > distanceLeft: vForward = distanceLeft / dt if vForward: self.vel.setY(vForward) self.mover.addShove(self.vel) if vH: self.rotVel.setX(vH) self.mover.addRotShove(self.rotVel)
def lookAtAv(self, av): avatar = simbase.air.doId2do.get(av) if avatar is None: return lookAtNode = NodePath('lookatNode') lookAtNode.hide() lookAtNode.reparentTo(self.pet) lookAtNode.lookAt(avatar) relH = reduceAngle(lookAtNode.getH(self.pet)) self.pet.d_setH(relH) # Hotfix for look bug; may look glitchy in-game del lookAtNode