new gravity handler

This commit is contained in:
Dave Schuyler 2004-04-14 01:27:34 +00:00
parent 6726f39637
commit d48b347dc3

View File

@ -74,6 +74,7 @@ class GravityWalker(DirectObject.DirectObject):
del self.doLaterTask del self.doLaterTask
#DirectObject.DirectObject.delete(self) #DirectObject.DirectObject.delete(self)
"""
def spawnTest(self): def spawnTest(self):
assert(self.debugPrint("\n\nspawnTest()\n")) assert(self.debugPrint("\n\nspawnTest()\n"))
if not self.wantDebugIndicator: if not self.wantDebugIndicator:
@ -156,6 +157,7 @@ class GravityWalker(DirectObject.DirectObject):
name='platformIval%s' % fakeId, name='platformIval%s' % fakeId,
) )
self.moveIval.loop() self.moveIval.loop()
"""
def setWalkSpeed(self, forward, jump, reverse, rotate): def setWalkSpeed(self, forward, jump, reverse, rotate):
assert(self.debugPrint("setWalkSpeed()")) assert(self.debugPrint("setWalkSpeed()"))
@ -169,9 +171,12 @@ class GravityWalker(DirectObject.DirectObject):
return (self.speed, self.rotationSpeed) return (self.speed, self.rotationSpeed)
def setupRay(self, bitmask, floorOffset): def setupRay(self, bitmask, floorOffset):
# This is a ray cast from your head down to detect floor polygons # 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 # This ray start is arbitrarily high in the air. Feel free to use
cRay = CollisionRay(0.0, 0.0, 4.0, 0.0, 0.0, -1.0) # a higher or lower value depending on whether you want an avatar
# that is outside of the world to step up to the floor when they
# get under valid floor:
cRay = CollisionRay(0.0, 0.0, 400000.0, 0.0, 0.0, -1.0)
cRayNode = CollisionNode('GW.cRayNode') cRayNode = CollisionNode('GW.cRayNode')
cRayNode.addSolid(cRay) cRayNode.addSolid(cRay)
self.cRayNodePath = self.avatarNodePath.attachNewNode(cRayNode) self.cRayNodePath = self.avatarNodePath.attachNewNode(cRayNode)
@ -270,6 +275,11 @@ class GravityWalker(DirectObject.DirectObject):
wallBitmask, floorBitmask, wallBitmask, floorBitmask,
avatarRadius = 1.4, floorOffset = 1.0): avatarRadius = 1.4, floorOffset = 1.0):
""" """
floorOffset is how high the avatar can reach. I.e. if the avatar
walks under a ledge that is <= floorOffset above the ground (a
double floor situation), the avatar will step up on to the
ledge (instantly).
Set up the avatar collisions Set up the avatar collisions
""" """
assert(self.debugPrint("initializeCollisions()")) assert(self.debugPrint("initializeCollisions()"))
@ -278,11 +288,8 @@ class GravityWalker(DirectObject.DirectObject):
self.avatarNodePath = avatarNodePath self.avatarNodePath = avatarNodePath
self.cTrav = collisionTraverser self.cTrav = collisionTraverser
# Changing this from zero may cause the avatar
# to float on the ground rather than landing properly:
self.floorOffset = 0.0
self.setupRay(floorBitmask, self.floorOffset) self.setupRay(floorBitmask, floorOffset)
self.setupWallSphere(wallBitmask, avatarRadius) self.setupWallSphere(wallBitmask, avatarRadius)
self.setupEventSphere(wallBitmask, avatarRadius) self.setupEventSphere(wallBitmask, avatarRadius)
if self.wantFloorSphere: if self.wantFloorSphere:
@ -535,8 +542,8 @@ class GravityWalker(DirectObject.DirectObject):
assert(self.debugPrint("enableAvatarControls()")) assert(self.debugPrint("enableAvatarControls()"))
assert self.collisionsActive assert self.collisionsActive
if __debug__: #*#if __debug__:
self.accept("control-f3", self.spawnTest) #*# #*# self.accept("control-f3", self.spawnTest) #*#
# remove any old # remove any old
if self.controlsTask: if self.controlsTask:
@ -549,8 +556,8 @@ class GravityWalker(DirectObject.DirectObject):
if self.fixCliffTask: if self.fixCliffTask:
self.fixCliffTask.remove() self.fixCliffTask.remove()
# spawn the new task # spawn the new task
taskName = "AvatarControls-FixCliff%s"%(id(self),) #*#taskName = "AvatarControls-FixCliff%s"%(id(self),)
self.fixCliffTask = taskMgr.add(self.FixCliff, taskName, 31) #*#self.fixCliffTask = taskMgr.add(self.FixCliff, taskName, 31)
self.isAirborne = 0 self.isAirborne = 0
self.mayJump = 1 self.mayJump = 1