Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | JymWythawhy | |
Old Version | Published before Godot 3 was released. |
Say I had a map object that was a dictionary that mapped tile locations (Vector2’s) to Tile Objects, which would hold information about that tile location, like the Tile Type (wall, floor, lava, etc), and if it contained a Unit (which could be empty, or the Player, or an ogre/zombie/weasel/whatever).
How could I check the Map location to see if a unit was contained there (map[Vector2].Unit != nil ?), and then see what kind of Unit was contained there? For this scenario, I would probably have a base Actor class that the Player and Enemy type would inherit from.
So, to further explain my goal- say an Enemy was at spot 1,1. The AI tells him to move one square east, so he tries to move to 2,1. The movement script would first check to see if that square is occupied. If it is not occupied, then the Enemy would complete the movement from 1,1 (which would now be unoccupied) to 2,1 (which would now be occupied by this Enemy. If, instead, 2,1 was occupied by another Enemy, nothing would happen, and the AI would chose another direction to try to move. If, in the third case, the space was occupied by the Player, the Enemy would deal damage to the Player, but would not move into the Player’s spot.
I am having trouble understanding your question - I think.
Could you not keep track of units as they move, and then use that data?
Tybobobo | 2016-11-01 16:48
What do you mean by keep track of the units?
I’ve added some more explanation up above- does that make sense?
JymWythawhy | 2016-11-01 18:34