GameMaker Assign several instances of an object to different paths

T

tonilatenz

Guest
Hej everyone. As the title already states, i would like to assign several instances of an object to different paths i set.
Lets say i have an "enemy" object which has a specific behaviour:
It follows a defined patrol path. If the player comes near the enemy, the enemy starts chasing the player (via grid based path finding).
If the player can flee and get out of sight, the enemy will return to its patrol path.

That works very well for 1 enemy. However, of course i want to have multiple of these enemies in one room. I only want each of them assigned to "his own" patrol path.

So i tried to do this via creation code for each instance, that didn't work.
What am i missing here?
By the way, i am using the room editor to place my enemies and don't use instance_create...the enemies are there at start.

So how can i let's say alter the value of the enemies variable "patrol_path" for each instance? Got a lot of weird stuff happening when trying with more than 1 instance.

Any help is much appreciated.
 
Weird stuff, like what? Giving a greater amount of detail about what's going wrong for you will help, as will including the code you are using :)

EDIT:
You are using GMS 2 and I don't, so it may be different. But still, people will want to know the above things. I might be able to help, until you include a bit more info it's hard to say.
 
K

kevins_office

Guest
If you are hard coding your enemies and paths, as in placing them in the IDE and designing their paths in the IDE, then have an instance variable in the enemy object, which you can define differently for each instance of the enemy telling it which is "his" path to follow when idle.

Say you have an enemy object "guard". In that object make an instance variable like "myPatrolPath = undefined;".

Then make your paths like Path_1, Path_2, etc

Place your guard object in the room editor, which creates instances of the guard object. In the room editor, after you have placed a guard object, double click it on one of the instances. It will open an instance window. In that window is a button that says [Creation Code]. Click that and it will open a code window. In that code window you write code specific to just that instance, not the object. So you can define a path for just that instance like "myPatrolPath = Path_2;".

Back in the event code for the guard object use the myPatrolPath variable to tell it which path to go back to when idle. So all instances will run that code telling to to go back to myPatrolPath which was defined differently for each instance in the room editor.
 
Top