S
Soco
Guest
I'm making a platformer with a player that has a cat following him around, but I'm having trouble getting the cat to follow him in a natural way. I'm currently using a ds_queue(a function that I only just discovered) to get the cat to follow him, but if anyone has a better idea, I'm open to suggestions. Anywho, here's my code as it stands now.
However, the cat doesn't react to solid objects...which is wierd sometimes. Also, if the player lands on a ledge, the cat just kinda floats in midair instead of falling to the ground. Could anybody tell me if I'm heading in the right direction to make the desired effect happen, or is there an easier function/code that I could be trying instead?
Code:
var dist = point_distance(x,y,obj_Player.x, obj_Player.y)
var dir = obj_Player.image_xscale;
if (dist >= 48){
//Follow
ds_queue_enqueue(followQueue, (obj_Player.x));
ds_queue_enqueue(followQueue, obj_Player.y);
lag_steps = 6;
if (ds_queue_size(followQueue) > lag_steps*2) {
x=ds_queue_dequeue(followQueue)-obj_Player.image_xscale*48; //xoffset
y=ds_queue_dequeue(followQueue)+2; //yoffset
image_xscale = dir; //makes the cat look the same direction as the player
}
}else{
ds_queue_dequeue(followQueue); //don't log while the player is within 48 pixels of the cat
}