Let's start with the homing, because "keeping objects on the grid" and "keeping objects from running through stuff" is logic you'll need in multiple places.Thanks, so all I have to do to determine which human is closer to which zombie is through this vector method as well?
Let's say the zombies are on the grid at location (x, y). And the nearest human object is at location (a, b). You can create a vector from (x, y) to (a, b) by subtracting (x, y) from (a, b). This vector is the amount you'd need to add to the zombies' location for them to be on top of the human.
For example, say the zombies are at (5, 8) and the human is at (12, 24). We subtract (5, 8) from (12, 24), getting (7, 16). And indeed, if you were to add (7, 16) to the zombies' location you'd be on top of the human.
Now of course, the zombies can't move that fast. Presumably they can only move one square at a time, and let's assume for now that they can't move diagonally. So take a look at that movement vector (7, 16). If they could only move in one direction, which direction would it be to get them closer to the human? They'd want to move downwards (assuming as always that Y distance increases as you go down, and X distance increases as you go right).
Of course, vectors can have negative components. If the human was to the left of the zombies, for example, then you might have a movement vector of (-8, 4). And even though -8 is smaller than 4, it's still the direction you want to move in. So you need to be careful to look at the magnitude of the movement vector, not just its amount.
Just use the absolute value. So if the vector is (3, -5) absolute value will make the values (3, 5). Since 5 is greater than three, add (0, -1).
And once he gets the vector for each human relative to the zombie, would he calculate the 'length'/magnitude of all the vectors (using Pythagorean theorem to calculate each?) and compare them to each other to find the shortest one and thus the closest human?I found a way to get the closest humans using GML, but I have three different types of humans, so I'm taking the distance formula of each of the three types and having it choose between the closest instance.
What would happen if 2 humans are at the exact same distance from the zombie?It will "prefer" one direction over another, although I haven't given it a preference yet. You probably would try to pull off the "put the zombie in the middle of moving people technique" but it falls apart as soon as you realise you are out numbered. I don't plan on having respawns yet, but if people are foling around then I might as well have a wave spawn offscreen every X turns.
And of course, what would he do once he implements obstacles? We cant have zombies bashing into walls to get the humans on the other side (unless in appropriate cases).I'll just have to write a code for that, but in the initial version a building would probably only give a bonus to defense, or even make you have to engage in CQC to drive them out.
So basicly, if you remove the zombie from the room/map it crashes? It may be that something is trying to mess with it and can't find it... it's been a while for me, but I believe there is a GML command for checking if an object exists. You'll want to make sure there is at least one of an object before trying to change/move/etc. it.Damn, there is? and I was wasting my time trying to get my game to count. It wasn't going well. I'll look for that command in the help files.
instance_number(obj) Returns the number of instances of type obj. obj can be an object or the keyword all.