Răsfoiți Sursa

added placeOnFloor()

Dave Schuyler 22 ani în urmă
părinte
comite
4d2f4dcc49

+ 3 - 0
direct/src/showbase/ControlManager.py

@@ -244,6 +244,9 @@ class ControlManager:
         assert(self.debugPrint("collisionsOff()"))
         assert(self.debugPrint("collisionsOff()"))
         self.currentControls.setCollisionsActive(0)
         self.currentControls.setCollisionsActive(0)
 
 
+    def placeOnFloor(self):
+        self.currentControls.placeOnFloor()
+
     def enable(self):
     def enable(self):
         assert(self.debugPrint("enable()"))
         assert(self.debugPrint("enable()"))
         self.isEnabled = 1
         self.isEnabled = 1

+ 20 - 12
direct/src/showbase/GravityWalker.py

@@ -97,31 +97,27 @@ class GravityWalker(DirectObject.DirectObject):
         self.platformRoot.setHpr(toonbase.localToon, Vec3.zero())
         self.platformRoot.setHpr(toonbase.localToon, Vec3.zero())
         self.platform.reparentTo(self.platformRoot)
         self.platform.reparentTo(self.platformRoot)
 
 
-        startPos = Vec3(0.0, -15.0, 0.0)
-        upPos = Vec3(0.0, 0.0, 15.0)
-        endPos = Vec3(0.0, 15.0, 0.0)
-        distance = Vec3(startPos-endPos).length()
-        duration = distance/4
+        duration = 7
         self.moveIval = Sequence(
         self.moveIval = Sequence(
             WaitInterval(0.3),
             WaitInterval(0.3),
             LerpPosInterval(self.platform, duration,
             LerpPosInterval(self.platform, duration,
-                            endPos, startPos=startPos,
+                            Vec3(0.0, 15.0, 0.0),
                             name='platformOut%s' % fakeId,
                             name='platformOut%s' % fakeId,
                             fluid = 1),
                             fluid = 1),
             WaitInterval(0.3),
             WaitInterval(0.3),
             LerpPosInterval(self.platform, duration,
             LerpPosInterval(self.platform, duration,
-                            startPos, startPos=endPos,
+                            Vec3(0.0, -15.0, 0.0),
                             name='platformBack%s' % fakeId,
                             name='platformBack%s' % fakeId,
                             fluid = 1),
                             fluid = 1),
             WaitInterval(0.3),
             WaitInterval(0.3),
             LerpPosInterval(self.platform, duration,
             LerpPosInterval(self.platform, duration,
-                            upPos,
-                            name='platformOut%s' % fakeId,
+                            Vec3(0.0, -15.0, 15.0),
+                            name='platformUp%s' % fakeId,
                             fluid = 1),
                             fluid = 1),
             WaitInterval(0.3),
             WaitInterval(0.3),
             LerpPosInterval(self.platform, duration,
             LerpPosInterval(self.platform, duration,
-                            startPos,
-                            name='platformOut%s' % fakeId,
+                            Vec3(0.0, -15.0, 0.0),
+                            name='platformDown%s' % fakeId,
                             fluid = 1),
                             fluid = 1),
 
 
             name='platformIval%s' % fakeId,
             name='platformIval%s' % fakeId,
@@ -232,6 +228,9 @@ class GravityWalker(DirectObject.DirectObject):
     def setAirborneHeightFunc(self, unused_parameter):
     def setAirborneHeightFunc(self, unused_parameter):
         self.getAirborneHeight = self.lifter.getAirborneHeight
         self.getAirborneHeight = self.lifter.getAirborneHeight
 
 
+    def getAirborneHeight(self):
+        self.lifter.getAirborneHeight()
+
     def setAvatarPhysicsIndicator(self, indicator):
     def setAvatarPhysicsIndicator(self, indicator):
         """
         """
         indicator is a NodePath
         indicator is a NodePath
@@ -290,6 +289,15 @@ class GravityWalker(DirectObject.DirectObject):
             self.oneTimeCollide()
             self.oneTimeCollide()
             self.cRayNodePath.setZ(temp)
             self.cRayNodePath.setZ(temp)
         return Task.cont
         return Task.cont
+    
+    def placeOnFloor(self):
+        """
+        Make a reasonable effor to place the avatar on the ground.
+        For example, this is useful when switching away from the 
+        current walker.
+        """
+        self.oneTimeCollide()
+        self.avatarNodePath.setZ(self.avatarNodePath.getZ()-self.lifter.getAirborneHeight())
 
 
     def oneTimeCollide(self):
     def oneTimeCollide(self):
         """
         """
@@ -303,7 +311,7 @@ class GravityWalker(DirectObject.DirectObject):
         tempCTrav.addCollider(self.cFloorSphereNodePath, self.event)
         tempCTrav.addCollider(self.cFloorSphereNodePath, self.event)
         tempCTrav.addCollider(self.cRayNodePath, self.lifter)
         tempCTrav.addCollider(self.cRayNodePath, self.lifter)
         tempCTrav.traverse(render)
         tempCTrav.traverse(render)
-    
+
     def setMayJump(self, task):
     def setMayJump(self, task):
         """
         """
         This function's use is internal to this class (maybe I'll add
         This function's use is internal to this class (maybe I'll add

+ 9 - 0
direct/src/showbase/NonPhysicsWalker.py

@@ -133,6 +133,15 @@ class NonPhysicsWalker(DirectObject.DirectObject):
                 # Now that we have disabled collisions, make one more pass
                 # Now that we have disabled collisions, make one more pass
                 # right now to ensure we aren't standing in a wall.
                 # right now to ensure we aren't standing in a wall.
                 self.oneTimeCollide()
                 self.oneTimeCollide()
+    
+    def placeOnFloor(self):
+        """
+        Make a reasonable effor to place the avatar on the ground.
+        For example, this is useful when switching away from the 
+        current walker.
+        """
+        self.oneTimeCollide()
+        self.setZ(self.getZ()-self.getAirborneHeight())
 
 
     def oneTimeCollide(self):
     def oneTimeCollide(self):
         """
         """

+ 9 - 0
direct/src/showbase/PhysicsWalker.py

@@ -374,6 +374,15 @@ class PhysicsWalker(DirectObject.DirectObject):
         assert(self.debugPrint("getCollisionsActive() returning=%s"%(
         assert(self.debugPrint("getCollisionsActive() returning=%s"%(
             self.collisionsActive,)))
             self.collisionsActive,)))
         return self.collisionsActive
         return self.collisionsActive
+    
+    def placeOnFloor(self):
+        """
+        Make a reasonable effor to place the avatar on the ground.
+        For example, this is useful when switching away from the 
+        current walker.
+        """
+        self.oneTimeCollide()
+        self.setZ(self.getZ()-self.getAirborneHeight())
 
 
     def oneTimeCollide(self):
     def oneTimeCollide(self):
         """
         """