unblock vertical aiming for combatants

This commit is contained in:
mrcheko 2014-04-28 16:34:49 +04:00
parent 22cdb166f2
commit 35c1724d39

View file

@ -34,13 +34,13 @@ namespace
float getZAngleToDir(const Ogre::Vector3& dir, float dirLen = 0.0f) float getZAngleToDir(const Ogre::Vector3& dir, float dirLen = 0.0f)
{ {
float len = (dirLen >= 0.0f)? dirLen : dir.length(); float len = (dirLen > 0.0f)? dirLen : dir.length();
return Ogre::Radian( Ogre::Math::ACos(dir.y / len) * sgn(Ogre::Math::ASin(dir.x / len)) ).valueDegrees(); return Ogre::Radian( Ogre::Math::ACos(dir.y / len) * sgn(Ogre::Math::ASin(dir.x / len)) ).valueDegrees();
} }
float getXAngleToDir(const Ogre::Vector3& dir, float dirLen = 0.0f) float getXAngleToDir(const Ogre::Vector3& dir, float dirLen = 0.0f)
{ {
float len = (dirLen >= 0.0f)? dirLen : dir.length(); float len = (dirLen > 0.0f)? dirLen : dir.length();
return Ogre::Radian(-Ogre::Math::ASin(dir.z / len)).valueDegrees(); return Ogre::Radian(-Ogre::Math::ASin(dir.z / len)).valueDegrees();
} }
@ -323,7 +323,6 @@ namespace MWMechanics
Ogre::Vector3 vActorPos(pos.pos); Ogre::Vector3 vActorPos(pos.pos);
Ogre::Vector3 vTargetPos(mTarget.getRefData().getPosition().pos); Ogre::Vector3 vTargetPos(mTarget.getRefData().getPosition().pos);
Ogre::Vector3 vDirToTarget = vTargetPos - vActorPos; Ogre::Vector3 vDirToTarget = vTargetPos - vActorPos;
float distToTarget = vDirToTarget.length();
bool isStuck = false; bool isStuck = false;
float speed = 0.0f; float speed = 0.0f;
@ -335,17 +334,19 @@ namespace MWMechanics
// check if actor can move along z-axis // check if actor can move along z-axis
bool canMoveByZ = (actorCls.canSwim(actor) && MWBase::Environment::get().getWorld()->isSwimming(actor)) bool canMoveByZ = (actorCls.canSwim(actor) && MWBase::Environment::get().getWorld()->isSwimming(actor))
|| MWBase::Environment::get().getWorld()->isFlying(actor); || MWBase::Environment::get().getWorld()->isFlying(actor);
if(canMoveByZ)
{ // determine vertical angle to target
// determine vertical angle to target // if actor can move along z-axis it will control movement dir
mMovement.mRotation[0] = getXAngleToDir(vDirToTarget, distToTarget); // if can't - it will control correct aiming
} mMovement.mRotation[0] = getXAngleToDir(vDirToTarget);
vDirToTarget.z = 0;
float distToTarget = vDirToTarget.length();
// (within strike dist) || (not quite strike dist while following) // (within strike dist) || (not quite strike dist while following)
if(distToTarget < rangeAttack || (distToTarget <= rangeFollow && mFollowTarget && !isStuck) ) if(distToTarget < rangeAttack || (distToTarget <= rangeFollow && mFollowTarget && !isStuck) )
{ {
//Melee and Close-up combat //Melee and Close-up combat
vDirToTarget.z = 0;
mMovement.mRotation[2] = getZAngleToDir(vDirToTarget, distToTarget); mMovement.mRotation[2] = getZAngleToDir(vDirToTarget, distToTarget);
// (not quite strike dist while following) // (not quite strike dist while following)