mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 13:53:51 +00:00
AiCombat: Avoid jittering when aiming in melee
This commit is contained in:
parent
e444b9581c
commit
15fa47827b
2 changed files with 20 additions and 9 deletions
|
@ -372,21 +372,32 @@ namespace MWMechanics
|
||||||
actorMovementSettings.mPosition[1] = storage.mMovement.mPosition[1];
|
actorMovementSettings.mPosition[1] = storage.mMovement.mPosition[1];
|
||||||
actorMovementSettings.mPosition[2] = storage.mMovement.mPosition[2];
|
actorMovementSettings.mPosition[2] = storage.mMovement.mPosition[2];
|
||||||
|
|
||||||
rotateActorOnAxis(actor, 2, actorMovementSettings, storage.mMovement);
|
rotateActorOnAxis(actor, 2, actorMovementSettings, storage);
|
||||||
rotateActorOnAxis(actor, 0, actorMovementSettings, storage.mMovement);
|
rotateActorOnAxis(actor, 0, actorMovementSettings, storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AiCombat::rotateActorOnAxis(const MWWorld::Ptr& actor, int axis,
|
void AiCombat::rotateActorOnAxis(const MWWorld::Ptr& actor, int axis,
|
||||||
MWMechanics::Movement& actorMovementSettings, MWMechanics::Movement& desiredMovement)
|
MWMechanics::Movement& actorMovementSettings, AiCombatStorage& storage)
|
||||||
{
|
{
|
||||||
actorMovementSettings.mRotation[axis] = 0;
|
actorMovementSettings.mRotation[axis] = 0;
|
||||||
float& targetAngleRadians = desiredMovement.mRotation[axis];
|
float& targetAngleRadians = storage.mMovement.mRotation[axis];
|
||||||
if (targetAngleRadians != 0)
|
if (targetAngleRadians != 0)
|
||||||
{
|
{
|
||||||
if (smoothTurn(actor, targetAngleRadians, axis))
|
// Some attack animations contain small amount of movement.
|
||||||
|
// Since we use cone shapes for melee, we can use a threshold to avoid jittering
|
||||||
|
std::shared_ptr<Action>& currentAction = storage.mCurrentAction;
|
||||||
|
bool isRangedCombat = false;
|
||||||
|
currentAction->getCombatRange(isRangedCombat);
|
||||||
|
// Check if the actor now facing desired direction, no need to turn any more
|
||||||
|
if (isRangedCombat)
|
||||||
{
|
{
|
||||||
// actor now facing desired direction, no need to turn any more
|
if (smoothTurn(actor, targetAngleRadians, axis))
|
||||||
targetAngleRadians = 0;
|
targetAngleRadians = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (smoothTurn(actor, targetAngleRadians, axis, osg::DegreesToRadians(3.f)))
|
||||||
|
targetAngleRadians = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -453,7 +464,7 @@ namespace MWMechanics
|
||||||
if (distToTarget <= rangeAttackOfTarget && Misc::Rng::rollClosedProbability() < 0.25)
|
if (distToTarget <= rangeAttackOfTarget && Misc::Rng::rollClosedProbability() < 0.25)
|
||||||
{
|
{
|
||||||
mMovement.mPosition[0] = Misc::Rng::rollProbability() < 0.5 ? 1.0f : -1.0f; // to the left/right
|
mMovement.mPosition[0] = Misc::Rng::rollProbability() < 0.5 ? 1.0f : -1.0f; // to the left/right
|
||||||
mTimerCombatMove = 0.05f + 0.15f * Misc::Rng::rollClosedProbability();
|
mTimerCombatMove = 0.1f + 0.1f * Misc::Rng::rollClosedProbability();
|
||||||
mCombatMove = true;
|
mCombatMove = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace MWMechanics
|
||||||
/// Transfer desired movement (from AiCombatStorage) to Actor
|
/// Transfer desired movement (from AiCombatStorage) to Actor
|
||||||
void updateActorsMovement(const MWWorld::Ptr& actor, float duration, AiCombatStorage& storage);
|
void updateActorsMovement(const MWWorld::Ptr& actor, float duration, AiCombatStorage& storage);
|
||||||
void rotateActorOnAxis(const MWWorld::Ptr& actor, int axis,
|
void rotateActorOnAxis(const MWWorld::Ptr& actor, int axis,
|
||||||
MWMechanics::Movement& actorMovementSettings, MWMechanics::Movement& desiredMovement);
|
MWMechanics::Movement& actorMovementSettings, AiCombatStorage& storage);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue