Announcement

Collapse
No announcement yet.

Help with Prioritizing a Target with the Least Distance and Health

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with Prioritizing a Target with the Least Distance and Health

    So I have an AI service that finds all enemies within a maximum distance from the AI. It makes sure each possible target has more than 0 health and that it can be seen. I have three arrays, PossibleTargets(character array), TargetDistances (float array), and TargetHealth (float array). Which I have populated with each target, their distance to the AI, and their current health.

    Click image for larger version

Name:	visionCheck.PNG
Views:	120
Size:	284.3 KB
ID:	1370735

    The question is: How do I find a target with the best of both worlds; the enemy that is the closest to the controlled AI and has the least health? (while still prioritizing the target that is closest)

    #2
    Perhaps I could add the two values together (at the same index) and add them to a fourth array and then find the lowest value of that array?
    Last edited by Mewbits; 10-17-2017, 10:37 AM.

    Comment


      #3
      There are many ways to do it :

      - You can make a secondary range where priority is based on health ( will have an impact on performence , many loops will be executed)
      Or:
      - You can also have the health having an impact on distance (ex. NewDistance = Distance - (1 - HealthRatio) * A_Value )
      Website [ LINK ]
      Twitter [ LINK ]
      Support ! [ LINK ]

      Comment


        #4
        Originally posted by Mhousse1247 View Post
        There are many ways to do it :

        - You can make a secondary range where priority is based on health ( will have an impact on performence , many loops will be executed)
        Or:
        - You can also have the health having an impact on distance (ex. NewDistance = Distance - (1 - HealthRatio) * A_Value )
        Okay I put together your second option. But, what exactly is the A_Value?

        Click image for larger version  Name:	A_Value.PNG Views:	1 Size:	71.4 KB ID:	1370887

        EDIT: Oh, I get it. the A_Value is how much the health will effect the distance?
        Last edited by Mewbits; 10-17-2017, 03:09 PM.

        Comment


          #5
          Yeah , (1 - HealthRatio) will give a value between 0 & 1 , and there is nothing really logical there A_Value will be based on tests (maybe 50 , 100,....)
          Website [ LINK ]
          Twitter [ LINK ]
          Support ! [ LINK ]

          Comment


            #6
            For the second way using 2 tests , here is a way to do it :

            1- Find the nearest enemy
            2- Find the lowest health in 2nd range ( nearest distance + X_Range)

            Click image for larger version

Name:	test457.PNG
Views:	94
Size:	313.3 KB
ID:	1370940

            Last edited by Mhousse1247; 10-17-2017, 05:01 PM.
            Website [ LINK ]
            Twitter [ LINK ]
            Support ! [ LINK ]

            Comment


              #7
              It's hard to say without knowing how your game works, but I think your implementation should depend on a few more factors than just distance and health. Anyway, I messed around with some values in a spreadsheet and I think I found a formula that works pretty well. The formula I used was distance * (health + a)b, and the values the seemed to give the best results were as follows:

              a = 3 (lowering this value causes the health to be favored)
              b = 2 (raising this value causes the health to be favored)

              After this calculate is done, you would iterate through each enemy and pick the lowest value. Note that the health has to be normalized to a 0-1 range. However, if all of your enemies have the same max health, then you would simply find this value with health / max health.


              Comment

              Working...
              X