AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=58)
-   -   Solved Calculate NAV distance between entities (https://forums.alliedmods.net/showthread.php?t=346423)

Mystik Spiral 02-23-2024 20:14

Calculate NAV distance between entities
 
I could use some help with how to calculate the NAVIGATION distance between two entities. I already know how to calculate the vector distance (that is what I am using now), but it does not work for enough scenarios.

Simple example... how far is it to the checkpoint?

Scenario: You are in a tunnel directly under the checkpoint, so your vector distance is very small. However, to get out of a long tunnel and navigate back to the checkpoint could be a very large distance.

How do I calculate the navigation distance to the checkpoint?

I suspect the "correct" answer involves a complex routine, but I do not need a precise answer... a good approximation will work fine. Perhaps something that calculates the Z angle between two entities and ignores anything higher than a certain angle?

I appreciate any help, thank you!

Mystik Spiral 02-23-2024 21:26

Re: Calculate NAV distance between entities
 
Here is more detail:

I want to prevent a bot from taking pain_pills when they are within a certain distance of the checkpoint (maybe 2250 hammer units), but I do not want to prevent them from using pain_pills if they are too close ONLY because they are under (or over) the checkpoint. I was thinking about calculating distance using only X.Y but ignore the value and return false (not too close) if the Z angle is more than about 20 to 30 degrees.

I do not need the actual navigation distance, just a boolean to help prevent bots from wasting pain_pills when they are close to the checkpoint.

While thinking about this, it seems funny that I cannot recall any maps where the checkpoint is entered vertically, like climbing/descending a ladder to the checkpoint and then closing a hatch in the floor/ceiling. The closest one I can think of is Death Aboard 2 map 3 (l4d_deathaboard03_docks).

Spirit_12 02-23-2024 22:46

Re: Calculate NAV distance between entities
 
You can easily do this with vscripts or Left4Dhooks. Here are the rough pointers.

Vscripts
  • Get map's flow via GetMaxFlowDistance.
  • Then you need to get GetLastKnownArea from your bot.
  • Use GetLastKnownArea /GetMaxFlowDistance to see how close is the bot to the checkpoint.
  • Block them from taking pills.

Left4dhooks
  • Get map's flow via L4D2Direct_GetMapMaxFlowDistance().
  • Then you need to get L4D_GetLastKnownArea from your bot.
  • Use L4D_GetLastKnownArea /L4D2Direct_GetMapMaxFlowDistance to see how close is the bot to the checkpoint.
  • Block them from taking pills.

Mystik Spiral 02-24-2024 07:56

Re: Calculate NAV distance between entities
 
Thank you @Spirit_12!

I am already using left4dhooks, so I will work on implementing that method. I had searched left4dhooks, but I was using the wrong keywords and missed this. Thanks again for you help!

Mystik Spiral 02-24-2024 10:31

Re: Calculate NAV distance between entities
 
OMG! This was so much easier than I anticipated. Already implemented and it was even simpler than what I was doing to calculate vector distance:

float dist = L4D2Direct_GetMapMaxFlowDistance() - L4D2Direct_GetFlowDistance(client);

Thanks @Spirit_12 and @Silvers!

Spirit_12 02-25-2024 22:59

Re: Calculate NAV distance between entities
 
Glad it worked out for you. I'm using the same technique to implement map events which is so much easier since I don't have to compile the map with each instance.


All times are GMT -4. The time now is 17:10.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.