mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
Make idle actors face the player. Turning animation is not smooth.
This commit is contained in:
parent
9bd31b6236
commit
3d26702f5e
1 changed files with 18 additions and 13 deletions
|
@ -204,9 +204,6 @@ namespace MWMechanics
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
zTurn(actor, Ogre::Degree(mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1])));
|
|
||||||
|
|
||||||
mReaction += duration;
|
mReaction += duration;
|
||||||
if(mReaction > 0.25f) // FIXME: hard coded constant
|
if(mReaction > 0.25f) // FIXME: hard coded constant
|
||||||
{
|
{
|
||||||
|
@ -375,32 +372,40 @@ namespace MWMechanics
|
||||||
helloDistance *= mGreetDistanceMultiplier;
|
helloDistance *= mGreetDistanceMultiplier;
|
||||||
|
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||||
float playerDist = Ogre::Vector3(player.getRefData().getPosition().pos).squaredDistance(
|
Ogre::Vector3 playerPos(player.getRefData().getPosition().pos);
|
||||||
Ogre::Vector3(actor.getRefData().getPosition().pos));
|
Ogre::Vector3 actorPos(actor.getRefData().getPosition().pos);
|
||||||
|
float playerDistSqr = playerPos.squaredDistance(actorPos);
|
||||||
|
|
||||||
if(mWalking && playerDist <= helloDistance*helloDistance)
|
if(playerDistSqr <= helloDistance*helloDistance)
|
||||||
{
|
{
|
||||||
stopWalking(actor);
|
if(mWalking)
|
||||||
mMoveNow = false;
|
{
|
||||||
mWalking = false;
|
stopWalking(actor);
|
||||||
mObstacleCheck.clear();
|
mMoveNow = false;
|
||||||
|
mWalking = false;
|
||||||
|
mObstacleCheck.clear();
|
||||||
|
}
|
||||||
|
Ogre::Vector3 dir = playerPos - actorPos;
|
||||||
|
float length = dir.length();
|
||||||
|
|
||||||
|
// FIXME: horrible hack, and does not turn smoothly
|
||||||
|
zTurn(actor, Ogre::Degree(Ogre::Radian(Ogre::Math::ACos(dir.y / length) * ((Ogre::Math::ASin(dir.x / length).valueRadians()>0)?1.0:-1.0)).valueDegrees()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mSaidGreeting)
|
if (!mSaidGreeting)
|
||||||
{
|
{
|
||||||
// TODO: check if actor is aware / has line of sight
|
// TODO: check if actor is aware / has line of sight
|
||||||
if (playerDist <= helloDistance*helloDistance
|
if (playerDistSqr <= helloDistance*helloDistance
|
||||||
// Only play a greeting if the player is not moving
|
// Only play a greeting if the player is not moving
|
||||||
&& Ogre::Vector3(player.getClass().getMovementSettings(player).mPosition).squaredLength() == 0)
|
&& Ogre::Vector3(player.getClass().getMovementSettings(player).mPosition).squaredLength() == 0)
|
||||||
{
|
{
|
||||||
mSaidGreeting = true;
|
mSaidGreeting = true;
|
||||||
MWBase::Environment::get().getDialogueManager()->say(actor, "hello");
|
MWBase::Environment::get().getDialogueManager()->say(actor, "hello");
|
||||||
// TODO: turn to face player and interrupt the idle animation?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (playerDist >= mGreetDistanceReset*mGreetDistanceReset * mGreetDistanceMultiplier*mGreetDistanceMultiplier)
|
if (playerDistSqr >= mGreetDistanceReset*mGreetDistanceReset * mGreetDistanceMultiplier*mGreetDistanceMultiplier)
|
||||||
mSaidGreeting = false;
|
mSaidGreeting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue