Another way to test if shoot is possible?

Hello.
Before watching the Code Monkey’s solution i’ve tried to challenge me to find the solution myself.
So i said me why don’t mimic move action with getLenghtPath.
For me it can work but I have a problem to transform targetUnit in something with gridPosition.
Here is my code :

                int pathLenghtMultiplier = 10;
                if(Pathfinding.Instance.GetPathLenght(unitGridPosition, targetUnit)> maxShootDistance*pathLenghtMultiplier)
                {
                    continue;
                }

It’s just to make advance the science, don’t worry but I love go in the crossroad :wink:

Thanks.
François

You can get the unit’s Gridposition with

targetUnit.GetGridPosition();

Are you talking about the part stopping it from shooting through walls?
Like that the only thing you’re testing is if it’s within a certain distance, it’s not testing if there’s a wall in the middle.
So if the unit is close enough, like just around the corner, it will shoot through the wall because technically it could move that far.

Hello teachers :slight_smile:
You’re right too.
By adding GetGridPosition() it works.
But you’re right donesn’t care about obstacles.
It’s logical, therre is a difference between the fcost to reach a tile and to shoot it :slight_smile:
But I notice a strange behavior for my second unit if I put it here, just behind the vault :

001

it stays here and make round trips at its round.

How does it react for you if you place it exactly here too ?
Thanks :wink:
François

It does what? It moves to that corner? If so yes that is intentional. When the EnemyAI does not find a target in range it will move to the position on the lower left corner (since all positions will have the same AI value it goes to the first one)

Privacy & Terms