Dr_Nomz
Member
I have a nice AI pathfinding system set up (courtesy of a video tutorial in the spoiler below) which works great for Zombie/follower AI, but unfortunately it's a system that takes up an unreasonable amount of CPU.
Now a solution I heard was just to run the code every so often instead of every single step, but when I put a timer on that code it just freezes the zombie, so really it's doing the exact opposite of what I need.
So what I need is to know how I can rearrange this code to work on a timer so it's not eating the CPU all the time, but without making the zombies just do nothing. (It would be really nice to have a simple timer that I can alter too, especially to add "random" so it doesn't freeze trying to process hundreds of enemies all at once every so often lol.)
That script is called to give the NPC (zombie) the path it needs to follow. (based on a grid that's created at the start of the room) In this case "target_x/y" can be anything, but is currently the obj_Character. (Player Character)
The zombie's code:
The "planner" is just an object with the create event for making the path in the first place, and then the zombie follows it from there. It's basically done this way to provide smoother movement.
^That's the zombie's create event, which creates the planner with the ID and everything it needs to function for that specific instance of obj_Zombie.
Basically I'm wondering if anything here "looks wrong", and if so please tell me immediately.
Here's the tutorial I used if anyone's interested:
Now I did have a thread for a similar question, but it didn't have all the information up top like this, and the thread's title wasn't very specific like it is now. (Also the answer was basically "Yes, if you run it every step.")
Now a solution I heard was just to run the code every so often instead of every single step, but when I put a timer on that code it just freezes the zombie, so really it's doing the exact opposite of what I need.
So what I need is to know how I can rearrange this code to work on a timer so it's not eating the CPU all the time, but without making the zombies just do nothing. (It would be really nice to have a simple timer that I can alter too, especially to add "random" so it doesn't freeze trying to process hundreds of enemies all at once every so often lol.)
Code:
target_x = argument0;
target_y = argument1;
mp_grid_path(grid,path,x,y,target_x,target_y,true);
path_start(path,100,path_action_stop,false);
The zombie's code:
Code:
///End Step
motion_add(point_direction(x,y,planner.x,planner.y),1);
if speed>5{
speed=5;
}
target_x = obj_Character.x;
target_y = obj_Character.y;
with (planner){
x=follower.x
y=follower.y
scr_NPC_Path(other.target_x,other.target_y);
}
Code:
planner = instance_create(x,y,obj_Path_Planner);
planner.follower = id;
Basically I'm wondering if anything here "looks wrong", and if so please tell me immediately.
Here's the tutorial I used if anyone's interested: