Browse Source

added takedown physics

Dave Schuyler 21 years ago
parent
commit
b79e18da3e
1 changed files with 15 additions and 9 deletions
  1. 15 9
      direct/src/controls/ShipPilot.py

+ 15 - 9
direct/src/controls/ShipPilot.py

@@ -76,7 +76,9 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
 
     def setAvatar(self, ship):
         self.ship = ship
-        if ship is not None:
+        if ship is None:
+            self.takedownPhysics()
+        else:
             #self.setupShip()
             self.setupPhysics(ship)
             
@@ -180,12 +182,23 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
 
         self.pusher.addCollider(self.cSphereNodePath, self.avatarNodePath)
 
+    def takedownPhysics(self):
+        assert(self.debugPrint("takedownPhysics()"))
+        if hasattr(self, "phys"):
+            del self.phys
+            for i in self.nodes:
+                i.removeNode()
+
     def setupPhysics(self, avatarNodePath):
         assert(self.debugPrint("setupPhysics()"))
         if avatarNodePath is None:
             return
         assert not avatarNodePath.isEmpty()
 
+        self.takedownPhysics()
+        self.nodes = []
+        self.phys=PhysicsManager.PhysicsManager()
+
         if 0:
             # Connect to Physics Manager:
             self.actorNode=ActorNode("ship-physicsActor")
@@ -204,14 +217,6 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
             self.actorNode = physicsActor.node()
             self.actorNode.getPhysicsObject().setOriented(1)
             self.actorNode.getPhysical(0).setViscosity(0.1)
-
-        if hasattr(self, "phys"):
-            del self.phys
-            for i in self.nodes:
-                i.removeNode()
-
-        self.nodes = []
-        self.phys=PhysicsManager.PhysicsManager()
         
         fn=ForceNode("ship gravity")
         fnp=NodePath(fn)
@@ -480,6 +485,7 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
             #    self.phys.debugOutput())
             onScreenDebug.add("orientation",
                 self.actorNode.getPhysicsObject().getOrientation().pPrintValues())
+            #print "ship orientation:", self.actorNode.getPhysicsObject().getOrientation().pPrintValues()
 
             momentumForce = self.momentumForce.getLocalVector()
             onScreenDebug.add("w momentumForce vec",