diff --git a/direct/src/controls/NonPhysicsWalker.py b/direct/src/controls/NonPhysicsWalker.py index 816d5f174e..755f0c85a2 100755 --- a/direct/src/controls/NonPhysicsWalker.py +++ b/direct/src/controls/NonPhysicsWalker.py @@ -184,14 +184,7 @@ class NonPhysicsWalker(DirectObject.DirectObject): """ onScreenDebug.add("controls", "NonPhysicsWalker") - def handleAvatarControls(self, task): - """ - Check on the arrow keys and update the avatar. - """ - if not self.lifter.hasContact(): - # hack fix for falling through the floor: - messenger.send("walkerIsOutOfWorld", [self.avatarNodePath]) - + def _calcSpeeds(self): # get the button states: forward = inputState.isSet("forward") reverse = inputState.isSet("reverse") @@ -209,7 +202,17 @@ class NonPhysicsWalker(DirectObject.DirectObject): self.rotationSpeed=not slide and ( (turnLeft and self.avatarControlRotateSpeed) or (turnRight and -self.avatarControlRotateSpeed)) - + + def handleAvatarControls(self, task): + """ + Check on the arrow keys and update the avatar. + """ + if not self.lifter.hasContact(): + # hack fix for falling through the floor: + messenger.send("walkerIsOutOfWorld", [self.avatarNodePath]) + + self._calcSpeeds() + if __debug__: debugRunning = inputState.isSet("debugRunning") if debugRunning: diff --git a/direct/src/controls/SwimWalker.py b/direct/src/controls/SwimWalker.py new file mode 100755 index 0000000000..43c42e35e5 --- /dev/null +++ b/direct/src/controls/SwimWalker.py @@ -0,0 +1,20 @@ +from direct.showbase.ShowBaseGlobal import * +from direct.directnotify import DirectNotifyGlobal +from direct.controls import NonPhysicsWalker + +class SwimWalker(NonPhysicsWalker.NonPhysicsWalker): + notify = DirectNotifyGlobal.directNotify.newCategory("SwimWalker") + + def _calcSpeeds(self): + # get the button states: + forward = inputState.isSet("forward") + reverse = inputState.isSet("reverse") + turnLeft = inputState.isSet("turnLeft") or inputState.isSet("slideLeft") + turnRight = inputState.isSet("turnRight") or inputState.isSet("slideRight") + # Determine what the speeds are based on the buttons: + self.speed=(forward and self.avatarControlForwardSpeed or + reverse and -self.avatarControlReverseSpeed) + self.slideSpeed=0. + self.rotationSpeed=( + (turnLeft and self.avatarControlRotateSpeed) or + (turnRight and -self.avatarControlRotateSpeed))