Skip to content

Commit

Permalink
Customizable Nav Mesh Gen Params
Browse files Browse the repository at this point in the history
Allows the navigation mesh generation parameters to be customized per implementation needs.
Bots will now crouch when the goal area is marked with the crouch attribute.
Changed ladder Z offset calculations.
  • Loading branch information
caxanga334 committed Dec 1, 2024
1 parent 2f0e8fd commit a6f95d0
Show file tree
Hide file tree
Showing 18 changed files with 317 additions and 284 deletions.
10 changes: 5 additions & 5 deletions extension/bot/interfaces/movement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void IMovement::ClimbLadder(const CNavLadder* ladder, CNavArea* dismount)
bot->DebugPrintToConsole(BOTDEBUG_MOVEMENT, 200, 0, 200, "%s CLIMBING LADDER! \n", bot->GetDebugIdentifier());

m_ladderExit->DrawFilled(255, 0, 255, 255, 5.0f, true);
NDebugOverlay::Text(m_ladderExit->GetCenter() + Vector(0.0f, 0.0f, StepHeight), "DISMOUNT AREA!", false, 5.0f);
NDebugOverlay::Text(m_ladderExit->GetCenter() + Vector(0.0f, 0.0f, navgenparams->step_height), "DISMOUNT AREA!", false, 5.0f);
}
}

Expand All @@ -346,7 +346,7 @@ void IMovement::DescendLadder(const CNavLadder* ladder, CNavArea* dismount)
bot->DebugPrintToConsole(BOTDEBUG_MOVEMENT, 200, 0, 200, "%s DESCENDING LADDER! \n", bot->GetDebugIdentifier());

m_ladderExit->DrawFilled(255, 0, 255, 255, 5.0f, true);
NDebugOverlay::Text(m_ladderExit->GetCenter() + Vector(0.0f, 0.0f, StepHeight), "DISMOUNT AREA!", false, 5.0f);
NDebugOverlay::Text(m_ladderExit->GetCenter() + Vector(0.0f, 0.0f, navgenparams->step_height), "DISMOUNT AREA!", false, 5.0f);
}
}

Expand Down Expand Up @@ -952,7 +952,7 @@ IMovement::LadderState IMovement::ApproachUpLadder()
{
// move to the ladder connection point (this is on the ladder)
MoveTowards(m_ladderMoveGoal);
FaceTowards(m_ladderMoveGoal + Vector(0.0f, 0.0f, HumanEyeHeight), true);
FaceTowards(m_ladderMoveGoal + Vector(0.0f, 0.0f, navgenparams->human_eye_height), true);

if (GetBot()->GetRangeTo(connection->GetConnectionPoint()) < CBaseExtPlayer::PLAYER_USE_RADIUS)
{
Expand Down Expand Up @@ -1284,7 +1284,7 @@ void IMovement::OnLadderStateChanged(LadderState oldState, LadderState newState)
case IMovement::USING_LADDER_UP:
{
// calculate Z goal
m_ladderGoalZ = m_ladder->GetConnectionToArea(m_ladderExit)->GetConnectionPoint().z - (GetStepHeight() / 4.0f);
m_ladderGoalZ = m_ladder->GetConnectionToArea(m_ladderExit)->GetConnectionPoint().z - (GetStepHeight() * 0.8f);
float time = m_ladder->m_length / LADDER_TIME_DIVIDER;
m_ladderTimer.Start(time);
return;
Expand All @@ -1300,7 +1300,7 @@ void IMovement::OnLadderStateChanged(LadderState oldState, LadderState newState)
case IMovement::USING_LADDER_DOWN:
{
// calculate Z goal
m_ladderGoalZ = m_ladder->GetConnectionToArea(m_ladderExit)->GetConnectionPoint().z + (GetStepHeight() / 4.0f);
m_ladderGoalZ = m_ladder->GetConnectionToArea(m_ladderExit)->GetConnectionPoint().z + (GetStepHeight() * 0.8f);
Vector lookAt = m_ladder->m_top;
lookAt.z = m_ladderGoalZ;
GetBot()->GetControlInterface()->SnapAimAt(lookAt, IPlayerController::LOOK_MOVEMENT);
Expand Down
12 changes: 12 additions & 0 deletions extension/bot/interfaces/path/meshnavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ void CMeshNavigator::Update(CBaseBot* bot)
return; // goal reached
}

CrouchIfNeeded(bot);

Vector origin = bot->GetAbsOrigin();
Vector forward = m_goal->goal - origin;
auto input = bot->GetControlInterface();
Expand Down Expand Up @@ -1215,6 +1217,16 @@ edict_t* CMeshNavigator::FindBlocker(CBaseBot* bot)
return nullptr;
}

void CMeshNavigator::CrouchIfNeeded(CBaseBot* bot)
{
constexpr auto GOAL_CROUCH_RANGE = 50.0f * 50.0f;

if (m_goal->area->HasAttributes(static_cast<int>(NavAttributeType::NAV_MESH_CROUCH)) || bot->GetRangeToSqr(m_goal->goal) <= GOAL_CROUCH_RANGE)
{
bot->GetControlInterface()->PressCrouchButton(0.1f);
}
}

bool CMeshNavigator::LadderUpdate(CBaseBot* bot)
{
auto input = bot->GetControlInterface();
Expand Down
1 change: 1 addition & 0 deletions extension/bot/interfaces/path/meshnavigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CMeshNavigator : public CPath
virtual bool JumpOverGaps(CBaseBot* bot, const CBasePathSegment* segment, const Vector& forward, const Vector& right, const float goalRange);
virtual Vector Avoid(CBaseBot* bot, const Vector& goalPos, const Vector& forward, const Vector& left);
virtual edict_t* FindBlocker(CBaseBot* bot);
virtual void CrouchIfNeeded(CBaseBot* bot);

private:
CBaseBot* m_me; // bot that is using this navigator
Expand Down
2 changes: 1 addition & 1 deletion extension/concommands_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ CON_COMMAND_F(sm_navbot_debug_find_ledge, "finds the ledge", FCVAR_CHEAT)
trace_t tr;
Vector pos1 = start + (forward * (stepSize * static_cast<float>(it)));
Vector pos2 = pos1;
pos2.z -= StepHeight;
pos2.z -= navgenparams->step_height;
trace::hull(pos1, pos2, mins, maxs, MASK_PLAYERSOLID, &filter, tr);

if (trace::pointoutisdeworld(pos1))
Expand Down
11 changes: 11 additions & 0 deletions extension/mods/tf2/nav/tfnavmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ CTFNavMesh::CTFNavMesh() : CNavMesh()
AddWalkableEntity("trigger_capture_area", true);
AddWalkableEntity("trigger_timer_door", true);
AddWalkableEntity("info_powerup_spawn");

navgenparams->half_human_width = 24.0f;
navgenparams->half_human_height = 41.0f;
navgenparams->human_height = 82.0f;
navgenparams->human_crouch_height = 62.0f;
navgenparams->human_eye_height = 74.0f;
navgenparams->human_crouch_eye_height = 44.0f;
navgenparams->jump_height = 49.0f;
navgenparams->jump_crouch_height = 68.0f;
navgenparams->climb_up_height = 68.0f;
navgenparams->death_drop = 220.0f; // experimental
}

CTFNavMesh::~CTFNavMesh()
Expand Down
56 changes: 22 additions & 34 deletions extension/navmesh/nav.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,30 @@
struct edict_t;

/**
* Below are several constants used by the navigation system.
* @todo Move these into TheNavMesh singleton.
* @brief Parameters used during nav mesh generation.
*/
constexpr float GenerationStepSize = 25.0f; // (30) was 20, but bots can't fit always fit
constexpr float JumpHeight = 41.8f; // if delta Z is less than this, we can jump up on it

#if defined(CSTRIKE_DLL)
constexpr float JumpCrouchHeight = 58.0f; // (48) if delta Z is less than or equal to this, we can jumpcrouch up on it
#else
constexpr float JumpCrouchHeight = 64.0f; // (48) if delta Z is less than or equal to this, we can jumpcrouch up on it
#endif

// There are 3 different definitions of StepHeight throughout the code, waiting to produce bugs if the 18.0 is ever changed.
constexpr float StepHeight = 18.0f; // if delta Z is greater than this, we have to jump to get up

// TERROR: Increased DeathDrop from 200, since zombies don't take falling damage
#if defined(CSTRIKE_DLL)
constexpr float DeathDrop = 200.0f; // (300) distance at which we will die if we fall - should be about 600, and pay attention to fall damage during pathfind
#else
constexpr float DeathDrop = 400.0f; // (300) distance at which we will die if we fall - should be about 600, and pay attention to fall damage during pathfind
#endif

#if defined(CSTRIKE_DLL)
constexpr float ClimbUpHeight = JumpCrouchHeight; // CSBots assume all jump up links are reachable
#else
constexpr float ClimbUpHeight = JumpCrouchHeight; //200.0f; // height to check for climbing up
#endif

// TERROR: Converted these values to use the same numbers as the player bounding boxes etc
constexpr auto HalfHumanWidth = 16.0f;
constexpr auto HalfHumanHeight = 35.5f;
constexpr auto HumanHeight = 71.0f;
constexpr auto HumanEyeHeight = 62.0f;
constexpr auto HumanCrouchHeight = 55.0f;
constexpr auto HumanCrouchEyeHeight = 37.0f;
class CNavMeshGeneratorParameters
{
public:
CNavMeshGeneratorParameters();


float generation_step_size;
float jump_height;
float jump_crouch_height;
float step_height;
float death_drop;
float climb_up_height;
float half_human_width; // half player standing hull width
float half_human_height; // half player standing hull height
float human_height; // player standing hull height
float human_eye_height; // player standing view height
float human_crouch_height; // player crouching hull height
float human_crouch_eye_height; // player crouching view height
};

// Global singleton for accessing the Navigation Mesh Generator Parameters
extern CNavMeshGeneratorParameters* navgenparams;

#define NAV_MAGIC_NUMBER 0xFEEDFACE // to help identify nav files

Expand Down
Loading

0 comments on commit a6f95d0

Please sign in to comment.