Following AI?
Hello all, i have a good few months of extensive experience with GS now, and so decided to try making a game. The game movement is supposed to be grid based. It is a rogue-like where the enemies only move if you are. I have movement set up with my player, and as there is no way to make a grid - that i could find anyways - i just told the player to change its position to self.positionX+40, and so on to simulate a grid. Because of this, i cant just tell the enemies to follow the player as they wont move on the grid like the player does. I'm trying to find a way to make the enemy decide which direction it would be best for it to move in based on how far away the player is. I have made the enemy track the players position, and have set up playerX and playerY attributes for the game. This is probably quite hard to understand so if you have any questions just ask. I would really appreciate any help of even just suggestions at this pint. Thanks in advance.
Answers
Enemy movement
Each turn:
Check player's row/col position on the grid
If my row ≠ player's row then
If my row < player's row then
Move to grid square in row [my row+1] and col [my col]
If my row > player's row then
Move to grid square in row [my row-1] and col [my col]
Else
If my column < player's column then
Move to grid square in row [my row] and col [my col+1]
If my column > player's column then
Move to grid square in row [my row] and col [my col-1]
Obviously, that's just a small snippet of the entire algorithm but perhaps that will offer you some insights into completing it.
Then if you need help with a specific step, just post your algorithm here and we can fill in the details about how to code it.
im aware this isnt the table grid that was mentioned before. can someone explain to me how to do the table grid, or point in the direction of a video? it would make the AI a lot easier to do. thanks for the help