Core/Units: Added Unit::SetFacingToPoint function

This commit is contained in:
Shauren
2023-03-05 15:45:57 +01:00
parent f83b161bcc
commit cdc09d29bc
4 changed files with 24 additions and 0 deletions

View File

@@ -12679,6 +12679,23 @@ void Unit::SetFacingToObject(WorldObject const* object, bool force)
init.Launch();
}
void Unit::SetFacingToPoint(Position const& point, bool force)
{
// do not face when already moving
if (!force && (!IsStopped() || !movespline->Finalized()))
return;
/// @todo figure out under what conditions creature will move towards object instead of facing it where it currently is.
Movement::MoveSplineInit init(this);
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZ(), false);
if (GetTransport())
init.DisableTransportPathTransformations(); // It makes no sense to target global orientation
init.SetFacing(point.GetPositionX(), point.GetPositionY(), point.GetPositionZ());
//GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_FACE, MOTION_PRIORITY_HIGHEST);
init.Launch();
}
bool Unit::SetWalk(bool enable)
{
if (enable == IsWalking())

View File

@@ -1248,6 +1248,7 @@ class TC_GAME_API Unit : public WorldObject
void SetInFront(WorldObject const* target);
void SetFacingTo(float const ori, bool force = true);
void SetFacingToObject(WorldObject const* object, bool force = true);
void SetFacingToPoint(Position const& point, bool force = true);
bool IsAlive() const { return (m_deathState == ALIVE); }
bool isDying() const { return (m_deathState == JUST_DIED); }

View File

@@ -220,6 +220,11 @@ namespace Movement
args.facing.type = MONSTER_MOVE_FACING_SPOT;
}
void MoveSplineInit::SetFacing(float x, float y, float z)
{
SetFacing({ x, y, z });
}
void MoveSplineInit::SetFacing(Unit const* target)
{
args.facing.angle = unit->GetAbsoluteAngle(target);

View File

@@ -87,6 +87,7 @@ namespace Movement
*/
void SetFacing(float angle);
void SetFacing(Vector3 const& point);
void SetFacing(float x, float y, float z);
void SetFacing(Unit const* target);
/* Initializes movement by path