Help! Changing Sprite with direction

K

kafka84

Guest
Hi,
I'm trying to change my enemy sprite to the direction it is moving

The code I'm trying to use is

Step)

switch (direction div 90)

{

case 0: sprite_index = spr_guard_run_right ; break;
case 1: sprite_index = spr_guard_run_left ; break;
case 2: sprite_index = spr_guard_run_down ; break;
case 3: sprite_index = spr_guard_run_up ; break;

}


Draw)

if xprevious = x && yprevious = y

draw_sprite (spr_sguard_d1, -1,x,y)

else

draw_sprite (sprite_index,-1,x,y)

The idle sprite does work when it is still but whenever the enemy object moves it only uses the run right sprite

Any idea where I'm going wrong?

Thanks
 

Nidoking

Member
How, precisely, is the object set to move toward the player object? I'm digging for information without which your question is unanswerable.
 
K

kafka84

Guest
Enemy chase script

var dis = point_distance(x,y,oPlayer.x,oPlayer.y) //distance from enemy to player
var inst = instance_nearest(x, y, oPlayer); //used to make enemy locate player
follow = 1; //if = 1, will not react to security camera


//Chase player if within aggro range
if (dis <= aggroRange)
{
mp_grid_path(global.grid,path,x,y,inst.x,inst.y,true);
path_start(path,3,path_action_stop,false);
}

//Look for player if NOT within aggro range
if (dis > aggroRange)
{
path_end();
state = state.search;
}

//Turn off init timelines while pursuing
timeline_index = tl_IdleSearch
timeline_running = false;


This part isn't my code
I haven't used Gamemaker in a while to code and I can only half remember what to do. I think I might need to learn again from scratch
 

Nidoking

Member
You're following a path, which means that speed and direction are not being set. You'll have to figure out the direction yourself, such as finding point_direction(xprevious, yprevious, x, y)
 
Top