From beb9eb025b6defe2a6dd01797d70707717caf9f5 Mon Sep 17 00:00:00 2001 From: Jason Yeung Date: Thu, 5 Oct 2006 04:35:34 +0000 Subject: [PATCH] - Added autosailing --- direct/src/controls/ShipPilot2.py | 33 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/direct/src/controls/ShipPilot2.py b/direct/src/controls/ShipPilot2.py index b7f0288a78..374e29dc90 100755 --- a/direct/src/controls/ShipPilot2.py +++ b/direct/src/controls/ShipPilot2.py @@ -63,6 +63,7 @@ class ShipPilot2(PhysicsWalker): self.__slideSpeed=0.0 self.__vel=Vec3(0.0) self.collisionsActive = 0 + self.currentTurning = 0.0 self.isAirborne = 0 self.highMark = 0 @@ -89,7 +90,8 @@ class ShipPilot2(PhysicsWalker): #self.setupShip() self.setupPhysics(ship) self.ship = ship - + + """ #*# Debug: if not hasattr(ship, "acceleration"): self.ship.acceleration = 60 @@ -100,7 +102,8 @@ class ShipPilot2(PhysicsWalker): self.ship.maxTurn = 30 self.ship.anchorDrag = .9 self.ship.hullDrag = .9 - + """ + def setupRay(self, floorBitmask, floorOffset): # This is a ray cast from your head down to detect floor polygons # A toon is about 4.0 feet high, so start it there @@ -593,6 +596,14 @@ class ShipPilot2(PhysicsWalker): jump = inputState.isSet("jump") # Determine what the speeds are based on the buttons: + # Check for Auto-Sailing + if self.ship.getIsAutoSailing(): + forward = 1 + reverse = 0 + + # How far did we move based on the amount of time elapsed? + dt=ClockObject.getGlobalClock().getDt() + # this was causing the boat to get stuck moving forward or back if 0: if not hasattr(self, "sailsDeployed"): @@ -611,8 +622,11 @@ class ShipPilot2(PhysicsWalker): self.sailsDeployed = -1.0 self.__speed = self.ship.acceleration * self.sailsDeployed else: - self.__speed=(forward and self.ship.acceleration or - reverse and -self.ship.reverseAcceleration) + self.__speed=(forward and self.ship.acceleration) or \ + (reverse and -self.ship.reverseAcceleration) + #self.__speed=(forward and min(dt*(self.__speed + self.ship.acceleration), self.ship.maxSpeed) or + # reverse and min(dt*(self.__speed - self.ship.reverseAcceleration), self.ship.maxReverseSpeed)) + avatarSlideSpeed=self.ship.acceleration*0.5 #self.__slideSpeed=slide and ( # (turnLeft and -avatarSlideSpeed) or @@ -623,8 +637,7 @@ class ShipPilot2(PhysicsWalker): self.__rotationSpeed=not slide and ( (turnLeft and self.ship.turnRate) or (turnRight and -self.ship.turnRate)) - - + # Enable debug turbo mode maxSpeed = self.ship.maxSpeed if __debug__: @@ -634,11 +647,8 @@ class ShipPilot2(PhysicsWalker): self.__slideSpeed*=4.0 self.__rotationSpeed*=1.25 maxSpeed = self.ship.maxSpeed * 4.0 - - + #*# - if not hasattr(self, "currentTurning"): - self.currentTurning = 0.0 self.currentTurning += self.__rotationSpeed if self.currentTurning > self.ship.maxTurn: self.currentTurning = self.ship.maxTurn @@ -659,9 +669,6 @@ class ShipPilot2(PhysicsWalker): if self.wantDebugIndicator: self.displayDebugInfo() - # How far did we move based on the amount of time elapsed? - dt=ClockObject.getGlobalClock().getDt() - if self.needToDeltaPos: self.setPriorParentVector() self.needToDeltaPos = 0