mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 18:15:35 +00:00
NPC always face you when fighting
This commit is contained in:
parent
a0edb55f60
commit
968968502e
1 changed files with 20 additions and 1 deletions
|
@ -9,6 +9,17 @@
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/mechanicsmanager.hpp"
|
#include "../mwbase/mechanicsmanager.hpp"
|
||||||
|
|
||||||
|
#include "OgreMath.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
static float sgn(float a)
|
||||||
|
{
|
||||||
|
if(a > 0)
|
||||||
|
return 1.0;
|
||||||
|
return -1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
@ -72,11 +83,19 @@ namespace MWMechanics
|
||||||
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
|
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
|
||||||
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1;
|
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1;
|
||||||
|
|
||||||
float range = 100;
|
|
||||||
|
|
||||||
|
float range = 100;
|
||||||
|
MWWorld::Class::get(actor).getCreatureStats(actor).setAttackingOrSpell(false);
|
||||||
if((dest.mX - start.mX)*(dest.mX - start.mX)+(dest.mY - start.mY)*(dest.mY - start.mY)+(dest.mZ - start.mZ)*(dest.mZ - start.mZ)
|
if((dest.mX - start.mX)*(dest.mX - start.mX)+(dest.mY - start.mY)*(dest.mY - start.mY)+(dest.mZ - start.mZ)*(dest.mZ - start.mZ)
|
||||||
< range*range)
|
< range*range)
|
||||||
{
|
{
|
||||||
|
float directionX = dest.mX - start.mX;
|
||||||
|
float directionY = dest.mY - start.mY;
|
||||||
|
float directionResult = sqrt(directionX * directionX + directionY * directionY);
|
||||||
|
|
||||||
|
zAngle = Ogre::Radian( acos(directionY / directionResult) * sgn(asin(directionX / directionResult)) ).valueDegrees();
|
||||||
|
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
|
||||||
|
|
||||||
mPathFinder.clearPath();
|
mPathFinder.clearPath();
|
||||||
|
|
||||||
MWWorld::TimeStamp time = MWBase::Environment::get().getWorld()->getTimeStamp();
|
MWWorld::TimeStamp time = MWBase::Environment::get().getWorld()->getTimeStamp();
|
||||||
|
|
Loading…
Reference in a new issue