mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-06-07 16:47:44 +00:00
fixed facing
This commit is contained in:
parent
b3ee248778
commit
12a2eae7fc
4 changed files with 14 additions and 5 deletions
|
@ -78,5 +78,14 @@ uint8_t Sapphire::Util::floatToUInt8Rot( float val )
|
||||||
float Sapphire::Util::RelativeAngle( float heading, float x1, float y1, float x2, float y2 )
|
float Sapphire::Util::RelativeAngle( float heading, float x1, float y1, float x2, float y2 )
|
||||||
{
|
{
|
||||||
float angle = ( (float)atan2( y2 - y1, x2 - x1 ) * ( 180.0 / PI ) );
|
float angle = ( (float)atan2( y2 - y1, x2 - x1 ) * ( 180.0 / PI ) );
|
||||||
return clamp( angle - heading , -180.0f, 180.0f );
|
float value = angle - heading;
|
||||||
|
|
||||||
|
float high = 180.0f;
|
||||||
|
float low = -180.0;
|
||||||
|
|
||||||
|
float range = high - low;
|
||||||
|
float modifier = ( ( int ) ( ( value - low ) / range ) - ( value < low ? 1 : 0 ) ) * range;
|
||||||
|
value -= modifier;
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ std::string Sapphire::Entity::Chara::getName() const
|
||||||
bool Sapphire::Entity::Chara::isFacing( Entity::CharaPtr target, float arcDegree )
|
bool Sapphire::Entity::Chara::isFacing( Entity::CharaPtr target, float arcDegree )
|
||||||
{
|
{
|
||||||
auto angleBetween = Util::RelativeAngle( getRot(), getPos().x, getPos().y, target->getPos().x, target->getPos().y );
|
auto angleBetween = Util::RelativeAngle( getRot(), getPos().x, getPos().y, target->getPos().x, target->getPos().y );
|
||||||
return angleBetween >= ( -( arcDegree / 2 ) && angleBetween <= ( arcDegree / 2 ) );
|
return angleBetween >= -( arcDegree / 2 ) && angleBetween <= ( arcDegree / 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \return current stance of the actors */
|
/*! \return current stance of the actors */
|
||||||
|
|
|
@ -160,7 +160,7 @@ namespace Sapphire::Entity
|
||||||
|
|
||||||
std::string getName() const;
|
std::string getName() const;
|
||||||
|
|
||||||
bool isFacing( Entity::CharaPtr target, float arcDegree = 100 );
|
bool isFacing( Entity::CharaPtr target, float arcDegree = 80 );
|
||||||
|
|
||||||
bool face( const Common::FFXIVARR_POSITION3& p );
|
bool face( const Common::FFXIVARR_POSITION3& p );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue