mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
fixes and changes to allow switching between walker controls.
This commit is contained in:
parent
28aba7f1a6
commit
e5c464101c
@ -124,6 +124,7 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||||||
del self.lifter
|
del self.lifter
|
||||||
|
|
||||||
def collisionsOff(self):
|
def collisionsOff(self):
|
||||||
|
assert(self.debugPrint("collisionsOff"))
|
||||||
self.cTrav.removeCollider(self.cSphereNode)
|
self.cTrav.removeCollider(self.cSphereNode)
|
||||||
self.cTrav.removeCollider(self.cRayNode)
|
self.cTrav.removeCollider(self.cRayNode)
|
||||||
|
|
||||||
@ -132,6 +133,7 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||||||
self.oneTimeCollide()
|
self.oneTimeCollide()
|
||||||
|
|
||||||
def collisionsOn(self):
|
def collisionsOn(self):
|
||||||
|
assert(self.debugPrint("collisionsOn"))
|
||||||
self.cTrav.addCollider(self.cSphereNode, self.pusher)
|
self.cTrav.addCollider(self.cSphereNode, self.pusher)
|
||||||
self.cTrav.addCollider(self.cRayNode, self.lifter)
|
self.cTrav.addCollider(self.cRayNode, self.lifter)
|
||||||
|
|
||||||
@ -193,6 +195,8 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||||||
"""
|
"""
|
||||||
Activate the arrow keys, etc.
|
Activate the arrow keys, etc.
|
||||||
"""
|
"""
|
||||||
|
assert(self.debugPrint("enableAvatarControls"))
|
||||||
|
print id(self), "NPW.enableAvatarControls()"
|
||||||
self.accept("control-arrow_left", self.moveTurnLeft, [1])
|
self.accept("control-arrow_left", self.moveTurnLeft, [1])
|
||||||
self.accept("control-arrow_left-up", self.moveTurnLeft, [0])
|
self.accept("control-arrow_left-up", self.moveTurnLeft, [0])
|
||||||
self.accept("control-arrow_right", self.moveTurnRight, [1])
|
self.accept("control-arrow_right", self.moveTurnRight, [1])
|
||||||
@ -210,6 +214,8 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||||||
self.accept("arrow_up-up", self.moveForward, [0])
|
self.accept("arrow_up-up", self.moveForward, [0])
|
||||||
self.accept("arrow_down", self.moveInReverse, [1])
|
self.accept("arrow_down", self.moveInReverse, [1])
|
||||||
self.accept("arrow_down-up", self.moveInReverse, [0])
|
self.accept("arrow_down-up", self.moveInReverse, [0])
|
||||||
|
|
||||||
|
self.collisionsOn()
|
||||||
|
|
||||||
taskName = "AvatarControls%s"%(id(self),)
|
taskName = "AvatarControls%s"%(id(self),)
|
||||||
# remove any old
|
# remove any old
|
||||||
@ -221,6 +227,8 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||||||
"""
|
"""
|
||||||
Ignore the arrow keys, etc.
|
Ignore the arrow keys, etc.
|
||||||
"""
|
"""
|
||||||
|
assert(self.debugPrint("disableAvatarControls"))
|
||||||
|
print id(self), "NPW.enableAvatarControls()"
|
||||||
taskName = "AvatarControls%s"%(id(self),)
|
taskName = "AvatarControls%s"%(id(self),)
|
||||||
taskMgr.remove(taskName)
|
taskMgr.remove(taskName)
|
||||||
|
|
||||||
@ -243,6 +251,8 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||||||
self.ignore("arrow_up-up")
|
self.ignore("arrow_up-up")
|
||||||
self.ignore("arrow_down")
|
self.ignore("arrow_down")
|
||||||
self.ignore("arrow_down-up")
|
self.ignore("arrow_down-up")
|
||||||
|
|
||||||
|
self.collisionsOff()
|
||||||
|
|
||||||
# reset state
|
# reset state
|
||||||
self.moveTurnLeft(0)
|
self.moveTurnLeft(0)
|
||||||
|
@ -28,7 +28,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
|
|
||||||
notify = DirectNotifyGlobal.directNotify.newCategory("PhysicsWalker")
|
notify = DirectNotifyGlobal.directNotify.newCategory("PhysicsWalker")
|
||||||
wantAvatarPhysicsIndicator = base.config.GetBool('want-avatar-physics-indicator', 0)
|
wantAvatarPhysicsIndicator = base.config.GetBool('want-avatar-physics-indicator', 0)
|
||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
def __init__(self, gravity = -32.1740, standableGround=0.707,
|
def __init__(self, gravity = -32.1740, standableGround=0.707,
|
||||||
hardLandingForce=16.0):
|
hardLandingForce=16.0):
|
||||||
@ -373,13 +373,19 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
onScreenDebug.add("physObject orien",
|
onScreenDebug.add("physObject orien",
|
||||||
physObject.getOrientation().pPrintValues())
|
physObject.getOrientation().pPrintValues())
|
||||||
|
|
||||||
|
if 1:
|
||||||
|
onScreenDebug.add("physObject vel",
|
||||||
|
physObject.getVelocity().pPrintValues())
|
||||||
|
onScreenDebug.add("physObject len",
|
||||||
|
"% 10.4f"%physObject.getVelocity().length())
|
||||||
|
|
||||||
if 0:
|
if 0:
|
||||||
onScreenDebug.add("posDelta4",
|
onScreenDebug.add("posDelta4",
|
||||||
self.priorParentNp.getRelativeVector(
|
self.priorParentNp.getRelativeVector(
|
||||||
render,
|
render,
|
||||||
self.avatarNodePath.getPosDelta(render)).pPrintValues())
|
self.avatarNodePath.getPosDelta(render)).pPrintValues())
|
||||||
|
|
||||||
if 0:
|
if 1:
|
||||||
onScreenDebug.add("priorParent",
|
onScreenDebug.add("priorParent",
|
||||||
self.priorParent.getLocalVector().pPrintValues())
|
self.priorParent.getLocalVector().pPrintValues())
|
||||||
|
|
||||||
@ -392,14 +398,16 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
self.__oldPosDelta.pPrintValues())
|
self.__oldPosDelta.pPrintValues())
|
||||||
|
|
||||||
if 1:
|
if 1:
|
||||||
onScreenDebug.add("__oldContact",
|
|
||||||
contact.pPrintValues())
|
|
||||||
onScreenDebug.add("contact",
|
onScreenDebug.add("contact",
|
||||||
contact.pPrintValues())
|
contact.pPrintValues())
|
||||||
onScreenDebug.add("__oldAirborneHeight", "% 10.4f"%(
|
|
||||||
self.getAirborneHeight(),))
|
|
||||||
onScreenDebug.add("airborneHeight", "% 10.4f"%(
|
onScreenDebug.add("airborneHeight", "% 10.4f"%(
|
||||||
self.getAirborneHeight(),))
|
self.getAirborneHeight(),))
|
||||||
|
|
||||||
|
if 0:
|
||||||
|
onScreenDebug.add("__oldContact",
|
||||||
|
contact.pPrintValues())
|
||||||
|
onScreenDebug.add("__oldAirborneHeight", "% 10.4f"%(
|
||||||
|
self.getAirborneHeight(),))
|
||||||
airborneHeight=self.getAirborneHeight()
|
airborneHeight=self.getAirborneHeight()
|
||||||
if airborneHeight > self.highMark:
|
if airborneHeight > self.highMark:
|
||||||
self.highMark = airborneHeight
|
self.highMark = airborneHeight
|
||||||
@ -407,7 +415,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
self.highMark,))
|
self.highMark,))
|
||||||
#if airborneHeight < 0.1: #contact!=Vec3.zero():
|
#if airborneHeight < 0.1: #contact!=Vec3.zero():
|
||||||
if 1:
|
if 1:
|
||||||
if airborneHeight > 0.7:
|
if airborneHeight > 0.7: # Check stair angles before chaning this.
|
||||||
# ...the avatar is airborne (maybe a lot or a tiny amount).
|
# ...the avatar is airborne (maybe a lot or a tiny amount).
|
||||||
self.isAirborne = 1
|
self.isAirborne = 1
|
||||||
else:
|
else:
|
||||||
@ -422,6 +430,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
else:
|
else:
|
||||||
#print "jumpLand"
|
#print "jumpLand"
|
||||||
messenger.send("jumpLand")
|
messenger.send("jumpLand")
|
||||||
|
self.priorParent.setVector(Vec3.zero())
|
||||||
self.isAirborne = 0
|
self.isAirborne = 0
|
||||||
elif self.__jumpButton:
|
elif self.__jumpButton:
|
||||||
#print "jump"
|
#print "jump"
|
||||||
@ -447,14 +456,11 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
# ...avatar was airborne.
|
# ...avatar was airborne.
|
||||||
self.jumpCount-=1
|
self.jumpCount-=1
|
||||||
if contactLength>self.__hardLandingForce:
|
if contactLength>self.__hardLandingForce:
|
||||||
print "jumpHardLand"
|
|
||||||
messenger.send("jumpHardLand")
|
messenger.send("jumpHardLand")
|
||||||
else:
|
else:
|
||||||
print "jumpLand"
|
|
||||||
messenger.send("jumpLand")
|
messenger.send("jumpLand")
|
||||||
elif self.__jumpButton:
|
elif self.__jumpButton:
|
||||||
self.jumpCount+=1
|
self.jumpCount+=1
|
||||||
print "jump"
|
|
||||||
self.__jumpButton=0
|
self.__jumpButton=0
|
||||||
messenger.send("jumpStart")
|
messenger.send("jumpStart")
|
||||||
jump=Vec3(contact+Vec3.up())
|
jump=Vec3(contact+Vec3.up())
|
||||||
@ -467,7 +473,15 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
# We must copy the vector to preserve it:
|
# We must copy the vector to preserve it:
|
||||||
self.__oldContact=Vec3(contact)
|
self.__oldContact=Vec3(contact)
|
||||||
self.__oldAirborneHeight=airborneHeight
|
self.__oldAirborneHeight=airborneHeight
|
||||||
self.phys.doPhysics(dt)
|
|
||||||
|
moveToGround = Vec3.zero()
|
||||||
|
if self.isAirborne:
|
||||||
|
# ...the airborne check is a hack to stop sliding.
|
||||||
|
self.phys.doPhysics(dt)
|
||||||
|
else:
|
||||||
|
physObject.setVelocity(Vec3.zero())
|
||||||
|
if airborneHeight>0.001 and contact==Vec3.zero():
|
||||||
|
moveToGround = Vec3(0.0, 0.0, -airborneHeight)
|
||||||
# Check to see if we're moving at all:
|
# Check to see if we're moving at all:
|
||||||
if self.__speed or self.__slideSpeed or self.__rotationSpeed:
|
if self.__speed or self.__slideSpeed or self.__rotationSpeed:
|
||||||
distance = dt * self.__speed
|
distance = dt * self.__speed
|
||||||
@ -489,7 +503,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
|
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
|
||||||
step=rotMat.xform(self.__vel)
|
step=rotMat.xform(self.__vel)
|
||||||
physObject.setPosition(Point3(
|
physObject.setPosition(Point3(
|
||||||
physObject.getPosition()+step))
|
physObject.getPosition()+step+moveToGround))
|
||||||
|
|
||||||
# update hpr:
|
# update hpr:
|
||||||
o=physObject.getOrientation()
|
o=physObject.getOrientation()
|
||||||
@ -614,7 +628,12 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
|
|
||||||
def setPriorParentVector(self):
|
def setPriorParentVector(self):
|
||||||
assert(self.debugPrint("doDeltaPos()"))
|
assert(self.debugPrint("doDeltaPos()"))
|
||||||
|
|
||||||
print "self.__oldDt", self.__oldDt, "self.__oldPosDelta", self.__oldPosDelta
|
print "self.__oldDt", self.__oldDt, "self.__oldPosDelta", self.__oldPosDelta
|
||||||
|
onScreenDebug.add("__oldDt", "% 10.4f"%self.__oldDt)
|
||||||
|
onScreenDebug.add("self.__oldPosDelta",
|
||||||
|
self.__oldPosDelta.pPrintValues())
|
||||||
|
|
||||||
velocity = self.__oldPosDelta*(1/self.__oldDt)
|
velocity = self.__oldPosDelta*(1/self.__oldDt)
|
||||||
assert(self.debugPrint(" __oldPosDelta=%s"%(self.__oldPosDelta,)))
|
assert(self.debugPrint(" __oldPosDelta=%s"%(self.__oldPosDelta,)))
|
||||||
assert(self.debugPrint(" velocity=%s"%(velocity,)))
|
assert(self.debugPrint(" velocity=%s"%(velocity,)))
|
||||||
@ -640,6 +659,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
Activate the arrow keys, etc.
|
Activate the arrow keys, etc.
|
||||||
"""
|
"""
|
||||||
assert(self.debugPrint("enableAvatarControls()"))
|
assert(self.debugPrint("enableAvatarControls()"))
|
||||||
|
print id(self), "PW.enableAvatarControls()"
|
||||||
self.accept("control", self.moveJump, [1])
|
self.accept("control", self.moveJump, [1])
|
||||||
self.accept("control-up", self.moveJump, [0])
|
self.accept("control-up", self.moveJump, [0])
|
||||||
self.accept("control-arrow_left", self.moveJumpLeft, [1])
|
self.accept("control-arrow_left", self.moveJumpLeft, [1])
|
||||||
@ -659,6 +679,8 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
self.accept("arrow_up-up", self.moveForward, [0])
|
self.accept("arrow_up-up", self.moveForward, [0])
|
||||||
self.accept("arrow_down", self.moveInReverse, [1])
|
self.accept("arrow_down", self.moveInReverse, [1])
|
||||||
self.accept("arrow_down-up", self.moveInReverse, [0])
|
self.accept("arrow_down-up", self.moveInReverse, [0])
|
||||||
|
|
||||||
|
self.collisionsOn()
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self.accept("control-f3", self.spawnTest) #*#
|
self.accept("control-f3", self.spawnTest) #*#
|
||||||
@ -677,6 +699,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
Ignore the arrow keys, etc.
|
Ignore the arrow keys, etc.
|
||||||
"""
|
"""
|
||||||
assert(self.debugPrint("disableAvatarControls()"))
|
assert(self.debugPrint("disableAvatarControls()"))
|
||||||
|
print id(self), "PW.disableAvatarControls()"
|
||||||
taskName = "AvatarControls%s"%(id(self),)
|
taskName = "AvatarControls%s"%(id(self),)
|
||||||
taskMgr.remove(taskName)
|
taskMgr.remove(taskName)
|
||||||
|
|
||||||
@ -702,7 +725,8 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
self.ignore("arrow_up-up")
|
self.ignore("arrow_up-up")
|
||||||
self.ignore("arrow_down")
|
self.ignore("arrow_down")
|
||||||
self.ignore("arrow_down-up")
|
self.ignore("arrow_down-up")
|
||||||
|
|
||||||
|
self.collisionsOff()
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self.ignore("control-f3") #*#
|
self.ignore("control-f3") #*#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user