• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Motion Planning and Pathing

T

Tyson Boyer

Guest
I am using a motion planning grid and the pathing functions to have my A.I chase the player. As far as I can tell, the path_start function only uses a positive speed to accomplish this motion, which means I cannot directly use the change in x or y (like I would with the player) as a way to know the direction the A.I is moving.

I was able to work around this by comparing the players x and y to the A.I's, but this way seems convoluted (maybe it is not, I am new to programming so all of my "work arounds" seem convoluted). Is there a way to get the A.I's x and y rate of change when using M.P grids and paths?
 

Corey

Member
I have something to consider, too. Like if you have a multitude of objects that you want the enemy to face at, I have an example of the enemy facing the nearest object. You can use this from a code of mine:

Step Event:
Code:
var bowangle = direction-90; // create a local variable 'bowangle' to set whatever direction to -90 (because my sprite is facing (up) 90 degrees, for some reason GMS likes sprites that are facing towards the right (0 degrees)).
if instance_exists(object) //check for the enemy object if it exists
{
    if (distance_to_object(object) <= finalRange) //finalRange = 600, this is defined in the create event.
    {
        inst = instance_nearest(x,y,object); //declare 'inst' as a variable for instance_nearest function
        var bowdirection = point_direction(x,y,inst.x,inst.y); //create a local variable 'bowdirection' to point towards the nearest object
        image_angle = bowangle + bowdirection; //set the image angle to 'bowangle' and 'bowdirection'. This is not necessary if your sprite is facing towards the right (0 degrees).
    }
    else
    {
        inst = noone; //reset inst variable to noone if there is nothing in range, but the object exists.
    }
}
if !instance_exists(object) //reset inst variable to noone if the object does not exist.
{
   inst = noone;
}
Create Event:
Code:
inst = noone;
finalRange = 600;
Keep in mind that the distance_to_object checks in all directions (like a circle) at the objects origin. Also, my object has a unique identifier assigned through a ds_map array.
 
Last edited:
Top