Raised This Month: $51 Target: $400
 12% 

Solved Calculate NAV distance between entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mystik Spiral
Senior Member
Join Date: Oct 2020
Location: Orlando, FL
Old 02-23-2024 , 20:14   Calculate NAV distance between entities
Reply With Quote #1

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!
__________________

Last edited by Mystik Spiral; 02-24-2024 at 10:35.
Mystik Spiral is offline
Mystik Spiral
Senior Member
Join Date: Oct 2020
Location: Orlando, FL
Old 02-23-2024 , 21:26   Re: Calculate NAV distance between entities
Reply With Quote #2

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).
__________________
Mystik Spiral is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 02-23-2024 , 22:46   Re: Calculate NAV distance between entities
Reply With Quote #3

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.
__________________
Spirit_12 is offline
Mystik Spiral
Senior Member
Join Date: Oct 2020
Location: Orlando, FL
Old 02-24-2024 , 07:56   Re: Calculate NAV distance between entities
Reply With Quote #4

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 is offline
Mystik Spiral
Senior Member
Join Date: Oct 2020
Location: Orlando, FL
Old 02-24-2024 , 10:31   Re: Calculate NAV distance between entities
Reply With Quote #5

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!
__________________
Mystik Spiral is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 02-25-2024 , 22:59   Re: Calculate NAV distance between entities
Reply With Quote #6

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.
__________________
Spirit_12 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:23.


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