Skip to content

Commit

Permalink
Merge branch 'aifollow' into 'master'
Browse files Browse the repository at this point in the history
Base AiFollow activation range on follow distance (bug #7685)

Closes #7685

See merge request OpenMW/openmw!3652
  • Loading branch information
jvoisin committed Dec 14, 2023
2 parents 3b1df3d + 5b02b77 commit c969aa4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
Bug #7665: Alchemy menu is missing the ability to deselect and choose different qualities of an apparatus
Bug #7675: Successful lock spell doesn't produce a sound
Bug #7679: Scene luminance value flashes when toggling shaders
Bug #7685: Corky sometimes doesn't follow Llovyn Andus
Bug #7712: Casting doesn't support spells and enchantments with no effects
Feature #3537: Shader-based water ripples
Feature #5173: Support for NiFogProperty
Expand Down
32 changes: 17 additions & 15 deletions apps/openmw/mwmechanics/aifollow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,6 @@ namespace MWMechanics
const osg::Vec3f targetPos(target.getRefData().getPosition().asVec3());
const osg::Vec3f targetDir = targetPos - actorPos;

// AiFollow requires the target to be in range and within sight for the initial activation
if (!mActive)
{
storage.mTimer -= duration;

if (storage.mTimer < 0)
{
if (targetDir.length2() < 500 * 500 && MWBase::Environment::get().getWorld()->getLOS(actor, target))
mActive = true;
storage.mTimer = 0.5f;
}
}
if (!mActive)
return false;

// In the original engine the first follower stays closer to the player than any subsequent followers.
// Followers beyond the first usually attempt to stand inside each other.
osg::Vec3f::value_type floatingDistance = 0;
Expand All @@ -152,6 +137,23 @@ namespace MWMechanics
floatingDistance += getHalfExtents(actor) * 2;
short followDistance = static_cast<short>(floatingDistance);

// AiFollow requires the target to be in range and within sight for the initial activation
if (!mActive)
{
storage.mTimer -= duration;

if (storage.mTimer < 0)
{
float activeRange = followDistance + 384.f;
if (targetDir.length2() < activeRange * activeRange
&& MWBase::Environment::get().getWorld()->getLOS(actor, target))
mActive = true;
storage.mTimer = 0.5f;
}
}
if (!mActive)
return false;

if (!mAlwaysFollow) // Update if you only follow for a bit
{
// Check if we've run out of time
Expand Down

0 comments on commit c969aa4

Please sign in to comment.