Make angular velocity depending on actor speed

To avoid moving in circles for actors with high speed.
pull/541/head
elsid 6 years ago
parent 56c9c72bc7
commit f684c90932
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -301,7 +301,7 @@ bool MWMechanics::AiPackage::checkWayIsClearForActor(const osg::Vec3f& startPoin
return true;
const float actorSpeed = actor.getClass().getSpeed(actor);
const float maxAvoidDist = AI_REACTION_TIME * actorSpeed + actorSpeed / MAX_VEL_ANGULAR_RADIANS * 2; // *2 - for reliability
const float maxAvoidDist = AI_REACTION_TIME * actorSpeed + actorSpeed / getAngularVelocity(actorSpeed) * 2; // *2 - for reliability
const float distToTarget = osg::Vec2f(endPoint.x(), endPoint.y()).length();
const float offsetXY = distToTarget > maxAvoidDist*1.5? maxAvoidDist : maxAvoidDist/2;
@ -363,7 +363,7 @@ bool MWMechanics::AiPackage::isReachableRotatingOnTheRun(const MWWorld::Ptr& act
// get actor's shortest radius for moving in circle
float speed = actor.getClass().getSpeed(actor);
speed += speed * 0.1f; // 10% real speed inaccuracy
float radius = speed / MAX_VEL_ANGULAR_RADIANS;
float radius = speed / getAngularVelocity(speed);
// get radius direction to the center
const float* rot = actor.getRefData().getPosition().rot;

@ -32,7 +32,7 @@ bool smoothTurn(const MWWorld::Ptr& actor, float targetAngleRadians, int axis, f
if (absDiff < epsilonRadians)
return true;
float limit = MAX_VEL_ANGULAR_RADIANS * MWBase::Environment::get().getFrameDuration();
float limit = getAngularVelocity(actor.getClass().getSpeed(actor)) * MWBase::Environment::get().getFrameDuration();
if (absDiff > limit)
diff = osg::sign(diff) * limit;

@ -3,6 +3,8 @@
#include <osg/Math>
#include <algorithm>
namespace MWWorld
{
class Ptr;
@ -12,7 +14,12 @@ namespace MWMechanics
{
// Max rotating speed, radian/sec
const float MAX_VEL_ANGULAR_RADIANS(10);
inline float getAngularVelocity(const float actorSpeed)
{
const float baseAngluarVelocity = 10;
const float baseSpeed = 200;
return baseAngluarVelocity * std::max(actorSpeed / baseSpeed, 1.0f);
}
/// configure rotation settings for an actor to reach this target angle (eventually)
/// @return have we reached the target angle?

Loading…
Cancel
Save