mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
strafe left and right support
This commit is contained in:
parent
dc8916d350
commit
71f3a958a1
@ -19,50 +19,38 @@ class BattleWalker(GravityWalker.GravityWalker):
|
||||
self.advanceSpeed = 0
|
||||
|
||||
def getSpeeds(self):
|
||||
#assert(self.debugPrint("getSpeeds()"))
|
||||
return (self.speed, self.rotationSpeed, self.slideSpeed, self.advanceSpeed)
|
||||
|
||||
|
||||
def handleAvatarControls(self, task):
|
||||
"""
|
||||
Check on the arrow keys and update the avatar.
|
||||
"""
|
||||
|
||||
# If targetNp is not available, revert back to GravityWalker.handleAvatarControls.
|
||||
# This situation occurs when the target dies, but we aren't switched out of
|
||||
# battle walker control mode.
|
||||
|
||||
targetNp = self.avatarNodePath.currentTarget
|
||||
if not BattleStrafe or targetNp == None or targetNp.isEmpty():
|
||||
return GravityWalker.GravityWalker.handleAvatarControls(self, task)
|
||||
|
||||
# get the button states:
|
||||
run = inputState.isSet("run")
|
||||
forward = inputState.isSet("forward")
|
||||
reverse = inputState.isSet("reverse")
|
||||
turnLeft = inputState.isSet("turnLeft")
|
||||
turnRight = inputState.isSet("turnRight")
|
||||
slide = inputState.isSet("slide")
|
||||
slideLeft = inputState.isSet("slideLeft")
|
||||
slideRight = inputState.isSet("slideRight")
|
||||
jump = inputState.isSet("jump")
|
||||
# Determine what the speeds are based on the buttons:
|
||||
self.advanceSpeed=(forward and self.avatarControlForwardSpeed or
|
||||
reverse and -self.avatarControlReverseSpeed)
|
||||
if run and self.advanceSpeed>0.0:
|
||||
self.advanceSpeed*=2.0 #*#
|
||||
# Should fSlide be renamed slideButton?
|
||||
self.slideSpeed=.15*(turnLeft and -self.avatarControlForwardSpeed or
|
||||
turnRight and self.avatarControlForwardSpeed)
|
||||
print 'slideSpeed: ', self.slideSpeed
|
||||
self.rotationSpeed=0
|
||||
self.speed=0
|
||||
|
||||
self.speed=(forward and self.avatarControlForwardSpeed or
|
||||
reverse and -self.avatarControlReverseSpeed)
|
||||
# Use reverse speed for strafe - that should be about what you want
|
||||
self.slideSpeed=(slideLeft and -self.avatarControlReverseSpeed or
|
||||
slideRight and self.avatarControlReverseSpeed)
|
||||
self.rotationSpeed=not (slideLeft or slideRight) and (
|
||||
(turnLeft and self.avatarControlRotateSpeed) or
|
||||
(turnRight and -self.avatarControlRotateSpeed))
|
||||
|
||||
if __debug__:
|
||||
debugRunning = inputState.isSet("debugRunning")
|
||||
if debugRunning:
|
||||
self.advanceSpeed*=4.0
|
||||
self.speed*=4.0
|
||||
self.slideSpeed*=4.0
|
||||
self.rotationSpeed*=1.25
|
||||
|
||||
|
||||
if self.needToDeltaPos:
|
||||
self.setPriorParentVector()
|
||||
self.needToDeltaPos = 0
|
||||
@ -100,76 +88,174 @@ class BattleWalker(GravityWalker.GravityWalker):
|
||||
self.__oldDt = ClockObject.getGlobalClock().getDt()
|
||||
dt=self.__oldDt
|
||||
|
||||
# Before we do anything with position or orientation, make the avatar
|
||||
# face it's target. Only allow rMax degrees rotation per frame, so
|
||||
# we don't get an unnatural spinning effect
|
||||
curH = self.avatarNodePath.getH()
|
||||
self.avatarNodePath.headsUp(targetNp)
|
||||
newH = self.avatarNodePath.getH()
|
||||
delH = reduceAngle(newH-curH)
|
||||
rMax = 10
|
||||
if delH < -rMax:
|
||||
self.avatarNodePath.setH(curH-rMax)
|
||||
self.rotationSpeed=-self.avatarControlRotateSpeed
|
||||
elif delH > rMax:
|
||||
self.avatarNodePath.setH(curH+rMax)
|
||||
self.rotationSpeed=self.avatarControlRotateSpeed
|
||||
|
||||
# Check to see if we're moving at all:
|
||||
self.moving = self.speed or self.slideSpeed or self.rotationSpeed or (self.priorParent!=Vec3.zero())
|
||||
if self.moving:
|
||||
distance = dt * self.speed
|
||||
slideDistance = dt * self.slideSpeed
|
||||
print 'slideDistance: ', slideDistance
|
||||
rotation = dt * self.rotationSpeed
|
||||
|
||||
# Take a step in the direction of our previous heading.
|
||||
self.vel=Vec3(Vec3.forward() * distance +
|
||||
Vec3.right() * slideDistance)
|
||||
if self.vel != Vec3.zero() or self.priorParent != Vec3.zero():
|
||||
if 1:
|
||||
# rotMat is the rotation matrix corresponding to
|
||||
# our previous heading.
|
||||
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
|
||||
step=(self.priorParent * dt) + rotMat.xform(self.vel)
|
||||
self.avatarNodePath.setFluidPos(Point3(
|
||||
self.avatarNodePath.getPos()+step))
|
||||
self.avatarNodePath.setH(self.avatarNodePath.getH()+rotation)
|
||||
else:
|
||||
self.vel.set(0.0, 0.0, 0.0)
|
||||
|
||||
"""
|
||||
# Check to see if we're moving at all:
|
||||
self.moving = self.advanceSpeed or self.slideSpeed or self.rotationSpeed or (self.priorParent!=Vec3.zero())
|
||||
if self.moving:
|
||||
distance = dt * self.advanceSpeed
|
||||
slideDistance = dt * self.slideSpeed
|
||||
rotation = dt * self.rotationSpeed
|
||||
|
||||
# Prevent avatar from getting too close to target
|
||||
d = self.avatarNodePath.getPos(targetNp)
|
||||
# TODO: make min distance adjust for current weapon
|
||||
if (d[0]*d[0]+d[1]*d[1] < 6.0 and distance > 0):
|
||||
# move the avatar sideways instead of forward
|
||||
slideDistance += .2
|
||||
distance = 0
|
||||
|
||||
# Take a step in the direction of our previous heading.
|
||||
self.vel=Vec3(Vec3.forward() * distance +
|
||||
Vec3.right() * slideDistance)
|
||||
if self.vel != Vec3.zero() or self.priorParent != Vec3.zero():
|
||||
# rotMat is the rotation matrix corresponding to
|
||||
# our previous heading.
|
||||
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
|
||||
step=rotMat.xform(self.vel) + (self.priorParent * dt)
|
||||
step=(self.priorParent * dt) + rotMat.xform(self.vel)
|
||||
self.avatarNodePath.setFluidPos(Point3(
|
||||
self.avatarNodePath.getPos()+step))
|
||||
self.avatarNodePath.setH(self.avatarNodePath.getH()+rotation)
|
||||
else:
|
||||
self.vel.set(0.0, 0.0, 0.0)
|
||||
"""
|
||||
if self.moving or jump:
|
||||
messenger.send("avatarMoving")
|
||||
return Task.cont
|
||||
|
||||
|
||||
|
||||
if 0:
|
||||
def handleAvatarControls(self, task):
|
||||
# If targetNp is not available, revert back to GravityWalker.handleAvatarControls.
|
||||
# This situation occurs when the target dies, but we aren't switched out of
|
||||
# battle walker control mode.
|
||||
|
||||
targetNp = self.avatarNodePath.currentTarget
|
||||
if not BattleStrafe or targetNp == None or targetNp.isEmpty():
|
||||
return GravityWalker.GravityWalker.handleAvatarControls(self, task)
|
||||
|
||||
# get the button states:
|
||||
run = inputState.isSet("run")
|
||||
forward = inputState.isSet("forward")
|
||||
reverse = inputState.isSet("reverse")
|
||||
turnLeft = inputState.isSet("turnLeft")
|
||||
turnRight = inputState.isSet("turnRight")
|
||||
slide = inputState.isSet("slide")
|
||||
jump = inputState.isSet("jump")
|
||||
# Determine what the speeds are based on the buttons:
|
||||
self.advanceSpeed=(forward and self.avatarControlForwardSpeed or
|
||||
reverse and -self.avatarControlReverseSpeed)
|
||||
if run and self.advanceSpeed>0.0:
|
||||
self.advanceSpeed*=2.0 #*#
|
||||
# Should fSlide be renamed slideButton?
|
||||
self.slideSpeed=.15*(turnLeft and -self.avatarControlForwardSpeed or
|
||||
turnRight and self.avatarControlForwardSpeed)
|
||||
print 'slideSpeed: ', self.slideSpeed
|
||||
self.rotationSpeed=0
|
||||
self.speed=0
|
||||
|
||||
if __debug__:
|
||||
debugRunning = inputState.isSet("debugRunning")
|
||||
if debugRunning:
|
||||
self.advanceSpeed*=4.0
|
||||
self.slideSpeed*=4.0
|
||||
self.rotationSpeed*=1.25
|
||||
|
||||
if self.needToDeltaPos:
|
||||
self.setPriorParentVector()
|
||||
self.needToDeltaPos = 0
|
||||
if self.wantDebugIndicator:
|
||||
self.displayDebugInfo()
|
||||
if self.lifter.isOnGround():
|
||||
if self.isAirborne:
|
||||
self.isAirborne = 0
|
||||
assert(self.debugPrint("isAirborne 0 due to isOnGround() true"))
|
||||
impact = self.lifter.getImpactVelocity()
|
||||
if impact < -30.0:
|
||||
messenger.send("jumpHardLand")
|
||||
self.startJumpDelay(0.3)
|
||||
else:
|
||||
messenger.send("jumpLand")
|
||||
if impact < -5.0:
|
||||
self.startJumpDelay(0.2)
|
||||
# else, ignore the little potholes.
|
||||
assert(self.isAirborne == 0)
|
||||
self.priorParent = Vec3.zero()
|
||||
if jump and self.mayJump:
|
||||
# The jump button is down and we're close
|
||||
# enough to the ground to jump.
|
||||
self.lifter.addVelocity(self.avatarControlJumpForce)
|
||||
messenger.send("jumpStart")
|
||||
self.isAirborne = 1
|
||||
assert(self.debugPrint("isAirborne 1 due to jump"))
|
||||
else:
|
||||
if self.isAirborne == 0:
|
||||
assert(self.debugPrint("isAirborne 1 due to isOnGround() false"))
|
||||
self.isAirborne = 1
|
||||
|
||||
self.__oldPosDelta = self.avatarNodePath.getPosDelta(render)
|
||||
# How far did we move based on the amount of time elapsed?
|
||||
self.__oldDt = ClockObject.getGlobalClock().getDt()
|
||||
dt=self.__oldDt
|
||||
|
||||
# Before we do anything with position or orientation, make the avatar
|
||||
# face it's target. Only allow rMax degrees rotation per frame, so
|
||||
# we don't get an unnatural spinning effect
|
||||
curH = self.avatarNodePath.getH()
|
||||
self.avatarNodePath.headsUp(targetNp)
|
||||
newH = self.avatarNodePath.getH()
|
||||
delH = reduceAngle(newH-curH)
|
||||
rMax = 10
|
||||
if delH < -rMax:
|
||||
self.avatarNodePath.setH(curH-rMax)
|
||||
self.rotationSpeed=-self.avatarControlRotateSpeed
|
||||
elif delH > rMax:
|
||||
self.avatarNodePath.setH(curH+rMax)
|
||||
self.rotationSpeed=self.avatarControlRotateSpeed
|
||||
|
||||
# Check to see if we're moving at all:
|
||||
self.moving = self.speed or self.slideSpeed or self.rotationSpeed or (self.priorParent!=Vec3.zero())
|
||||
if self.moving:
|
||||
distance = dt * self.speed
|
||||
slideDistance = dt * self.slideSpeed
|
||||
print 'slideDistance: ', slideDistance
|
||||
rotation = dt * self.rotationSpeed
|
||||
|
||||
# Take a step in the direction of our previous heading.
|
||||
self.vel=Vec3(Vec3.forward() * distance +
|
||||
Vec3.right() * slideDistance)
|
||||
if self.vel != Vec3.zero() or self.priorParent != Vec3.zero():
|
||||
if 1:
|
||||
# rotMat is the rotation matrix corresponding to
|
||||
# our previous heading.
|
||||
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
|
||||
step=(self.priorParent * dt) + rotMat.xform(self.vel)
|
||||
self.avatarNodePath.setFluidPos(Point3(
|
||||
self.avatarNodePath.getPos()+step))
|
||||
self.avatarNodePath.setH(self.avatarNodePath.getH()+rotation)
|
||||
else:
|
||||
self.vel.set(0.0, 0.0, 0.0)
|
||||
|
||||
"""
|
||||
# Check to see if we're moving at all:
|
||||
self.moving = self.advanceSpeed or self.slideSpeed or self.rotationSpeed or (self.priorParent!=Vec3.zero())
|
||||
if self.moving:
|
||||
distance = dt * self.advanceSpeed
|
||||
slideDistance = dt * self.slideSpeed
|
||||
rotation = dt * self.rotationSpeed
|
||||
|
||||
# Prevent avatar from getting too close to target
|
||||
d = self.avatarNodePath.getPos(targetNp)
|
||||
# TODO: make min distance adjust for current weapon
|
||||
if (d[0]*d[0]+d[1]*d[1] < 6.0 and distance > 0):
|
||||
# move the avatar sideways instead of forward
|
||||
slideDistance += .2
|
||||
distance = 0
|
||||
|
||||
# Take a step in the direction of our previous heading.
|
||||
self.vel=Vec3(Vec3.forward() * distance +
|
||||
Vec3.right() * slideDistance)
|
||||
if self.vel != Vec3.zero() or self.priorParent != Vec3.zero():
|
||||
# rotMat is the rotation matrix corresponding to
|
||||
# our previous heading.
|
||||
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
|
||||
step=rotMat.xform(self.vel) + (self.priorParent * dt)
|
||||
self.avatarNodePath.setFluidPos(Point3(
|
||||
self.avatarNodePath.getPos()+step))
|
||||
self.avatarNodePath.setH(self.avatarNodePath.getH()+rotation)
|
||||
else:
|
||||
self.vel.set(0.0, 0.0, 0.0)
|
||||
"""
|
||||
if self.moving or jump:
|
||||
messenger.send("avatarMoving")
|
||||
return Task.cont
|
||||
|
||||
|
||||
|
@ -71,28 +71,29 @@ class ControlManager:
|
||||
inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop")
|
||||
|
||||
inputState.watch("jump", "control", "control-up")
|
||||
|
||||
if __dev__:
|
||||
inputState.watch("slideLeft", "home", "home-up")
|
||||
inputState.watch("slideRight", "end", "end-up")
|
||||
inputState.watch("levitateUp", "page_up", "page_up-up")
|
||||
inputState.watch("levitateDown", "page_down", "page_down-up")
|
||||
inputState.watch("run", "shift", "shift-up")
|
||||
|
||||
inputState.watch("slideLeft", "home", "home-up")
|
||||
inputState.watch("slideRight", "end", "end-up")
|
||||
inputState.watch("levitateUp", "page_up", "page_up-up")
|
||||
inputState.watch("levitateDown", "page_down", "page_down-up")
|
||||
inputState.watch("run", "shift", "shift-up")
|
||||
# FYI, ghost mode uses jump for slide.
|
||||
# inputState.watch("slide", "slide-is-disabled", "slide-is-disabled")
|
||||
inputState.watch("slide", "mouse3", "mouse3-up")
|
||||
|
||||
# FYI, ghost mode uses jump for slide.
|
||||
#inputState.watch("slide", "slide-is-disabled", "slide-is-disabled")
|
||||
inputState.watch("slide", "mouse3", "mouse3-up")
|
||||
|
||||
#inputState.watch("slideLeft", "shift-arrow_left", "shift-arrow_left-up")
|
||||
#inputState.watch("slideLeft", "control-arrow_left", "control-arrow_left-up")
|
||||
#inputState.watch("slideLeft", "alt-arrow_left", "alt-arrow_left-up")
|
||||
#inputState.watch("slideLeft", "shift-arrow_left", "shift-arrow_left-up")
|
||||
#inputState.watch("slideLeft", "slide-is-disabled", "slide-is-disabled")
|
||||
|
||||
#inputState.watch("slideRight", "shift-arrow_right", "shift-arrow_right-up")
|
||||
#inputState.watch("slideRight", "control-arrow_right", "control-arrow_right-up")
|
||||
#inputState.watch("slideRight", "alt-arrow_right", "alt-arrow_right-up")
|
||||
#inputState.watch("slideRight", "shift-arrow_right", "shift-arrow_right-up")
|
||||
#inputState.watch("slideRight", "slide-is-disabled", "slide-is-disabled")
|
||||
# inputState.watch("slideLeft", "shift-arrow_left", "shift-arrow_left-up")
|
||||
# inputState.watch("slideLeft", "control-arrow_left", "control-arrow_left-up")
|
||||
# inputState.watch("slideLeft", "alt-arrow_left", "alt-arrow_left-up")
|
||||
# inputState.watch("slideLeft", "shift-arrow_left", "shift-arrow_left-up")
|
||||
# inputState.watch("slideLeft", "slide-is-disabled", "slide-is-disabled")
|
||||
|
||||
# inputState.watch("slideRight", "shift-arrow_right", "shift-arrow_right-up")
|
||||
# inputState.watch("slideRight", "control-arrow_right", "control-arrow_right-up")
|
||||
# inputState.watch("slideRight", "alt-arrow_right", "alt-arrow_right-up")
|
||||
# inputState.watch("slideRight", "shift-arrow_right", "shift-arrow_right-up")
|
||||
# inputState.watch("slideRight", "slide-is-disabled", "slide-is-disabled")
|
||||
|
||||
if self.wantWASD:
|
||||
inputState.watch("forward", "w", "w-up")
|
||||
|
@ -165,7 +165,7 @@ class GravityWalker(DirectObject.DirectObject):
|
||||
|
||||
def getSpeeds(self):
|
||||
#assert(self.debugPrint("getSpeeds()"))
|
||||
return (self.speed, self.rotationSpeed)
|
||||
return (self.speed, self.rotationSpeed, self.slideSpeed)
|
||||
|
||||
def setAvatar(self, avatar):
|
||||
self.avatar = avatar
|
||||
@ -448,18 +448,16 @@ class GravityWalker(DirectObject.DirectObject):
|
||||
reverse = inputState.isSet("reverse")
|
||||
turnLeft = inputState.isSet("turnLeft")
|
||||
turnRight = inputState.isSet("turnRight")
|
||||
slide = 0 #hack -- was: inputState.isSet("slide")
|
||||
slideLeft = inputState.isSet("slideLeft")
|
||||
slideRight = inputState.isSet("slideRight")
|
||||
jump = inputState.isSet("jump")
|
||||
# Determine what the speeds are based on the buttons:
|
||||
self.speed=(forward and self.avatarControlForwardSpeed or
|
||||
reverse and -self.avatarControlReverseSpeed)
|
||||
#if run and self.speed>0.0:
|
||||
# self.speed*=2.0 #*#
|
||||
# Should fSlide be renamed slideButton?
|
||||
self.slideSpeed=slide and (
|
||||
(turnLeft and -self.avatarControlForwardSpeed) or
|
||||
(turnRight and self.avatarControlForwardSpeed))
|
||||
self.rotationSpeed=not slide and (
|
||||
# Use reverse speed for strafe - that should be about what you want
|
||||
self.slideSpeed=(slideLeft and -self.avatarControlReverseSpeed or
|
||||
slideRight and self.avatarControlReverseSpeed)
|
||||
self.rotationSpeed=not (slideLeft or slideRight) and (
|
||||
(turnLeft and self.avatarControlRotateSpeed) or
|
||||
(turnRight and -self.avatarControlRotateSpeed))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user