Facepunch / garrysmod-requests

Feature requests for Garry's Mod
86 stars 24 forks source link

Bind NEXTBOT:GetEyePosition (IBody::GetEyePosition) to Lua or add SetEyeOffset and GetEyeOffset methods #2280

Open justin-chellah opened 10 months ago

justin-chellah commented 10 months ago

Details

Similar to #2171, there's currently no way to override the GetEyePosition for Nextbots. It returns the WorldSpaceCenter as the eye position and having this change would make Visible, VisibleVec, IsLineOfSightClear, IsAbleToSee, and the vision interface (IVision) useful again.

I would propose adding a Vector m_eyeOffset; to the CLuaNextBotBody class and then overriding this method:

virtual const Vector &GetEyePosition( void ) const override;
const Vector &CLuaNextBotBody::GetEyePosition( void ) const
{
    static Vector eye;

    eye = GetBot()->GetEntity()->GetAbsOrigin() + m_eyeOffset;

    return eye;
}
CLuaNextBotBody::CLuaNextBotBody( INextBot *bot )
{
    m_eyeOffset = vec3_origin;
}

Then:

CLuaNextBot::Spawn()
{
    BaseClass::Spawn();

    ...

    // default in IBody::GetEyePosition()
    GetBodyInterface()->m_eyeOffset = WorldSpaceCenter() - GetAbsOrigin();

    // ENT:Initialize down here
}

And to set and get the eye offset, you could add methods like NEXTBOT:SetEyeOffset and NEXTBOT:GetEyeOffset. Devs can then set the eye offset in ENT:Initialize.

This approach is based on TF2 for the CBotNPCArcher. See here: https://github.com/lua9520/source-engine-2018-hl2_src/blob/3bf9df6b2785fa6d951086978a3e66f49427166a/game/server/tf/bot_npc/bot_npc_archer.h and https://github.com/lua9520/source-engine-2018-hl2_src/blob/3bf9df6b2785fa6d951086978a3e66f49427166a/game/server/tf/bot_npc/bot_npc_archer.cpp