I'm sorry for such a simple question, but I can't seem to find a straightforward answer to this.
My AI enemies choose a target direction to face before moving.
I have one tilechecker sprite that checks for obstacles before allowing my AI enemies to face and move in said direction.
With that, I have an array where my enemies will keep track of all of their possible directions they can face.
If the tilechecker covers an obstacle, they need to remember that they cannot go in that direction anymore so that target direction is deleted from the array before checking for another suitable direction until it finds a clear direction to start facing. This is to prevent enemies rotating to face a direction they cannot go in and look silly.
I want my enemies to pick a random available direction that is in the array, but I am doing this a bit wrong I think.
Whenever I set i_TargetDirection to random(enemy.IndexOf(enemy.i_TargetDirection))
Instead of picking these values:
It picks these values:
Or in the case of the above expression example it actually randomises the number like 0.5234523452345 and ignores the fact that I want to select from the enemy's instance variable.
What's weird about this is I can choose to delete the value accurately with Self.IndexOf(Enemy.i_TargetDirection) on the array object. But how do I randomly pick a range of values stored in the array and not the element number? If I delete the element number, the element numbers re-count themselves and it changes, the values stored don't do this, and my enemy gets stuck going into an obstacle they can't move through because the wrong value was deleted from the array.
Also for your information, the i_TargetDirection values mean the following:
0 = idle (This is not seen in the array because it is not a value that is used to tell the character to face a direction)
1 = right
2 = Down
3 = Left
4 = Up
Your assistance is greatly appreciated. Thanks!