Legacy GM enemies don't turn right away (SOLVED)

Y

Yvalson

Guest
so I have enemies that move along a grid as they follow the path to the player.

I have make them change sprites if their direction changes but for some reason it always takes like 2 seconds before the sprites are the good ones

here is the code:
///movement

if( direction = 0){
sprite_index = Spr_Mognorian_Walk_Right
}
if( direction = 90){
sprite_index = Spr_Mognorian_Walk_Up
}
if( direction = 180){
sprite_index = Spr_Mognorian_Walk_Left
}
if( direction = 270){
sprite_index = Spr_Mognorian_Walk_Down
}

if(path_position = 1){
if( direction = 0){
sprite_index = Spr_Mognorian_Idle_Right
}
if( direction = 90){
sprite_index = Spr_Mognorian_Idle_Up
}
if( direction = 180){
sprite_index = Spr_Mognorian_Idle_Left
}
if( direction = 270){
sprite_index = Spr_Mognorian_Idle_Down
}
}

if(path_speed = 0){
if( direction = 0){
sprite_index = Spr_Mognorian_Idle_Right
}
if( direction = 90){
sprite_index = Spr_Mognorian_Idle_Up
}
if( direction = 180){
sprite_index = Spr_Mognorian_Idle_Left
}
if( direction = 270){
sprite_index = Spr_Mognorian_Idle_Down
}
}

///path

RepothPosx = (Obj_Repoth1.x div 20) * 20 + 10
RepothPosy = (Obj_Repoth1.y div 20) * 20 + 10

alarm[0] = 30

//follow path


if (mp_grid_path(global.grid, path, x, y, RepothPosx, RepothPosy, 0)){
path_start (path, 1, path_action_stop, false)
}
 
D

David Berkompas

Guest
I'm very, very new to GMS, but shouldn't you be using ==, a single = is usually an assignment statement.


Dave
 

Rivo

7014
I'm very, very new to GMS, but shouldn't you be using ==, a single = is usually an assignment statement.


Dave
It's good to get in the habit of doing that, since that's the proper way to do it. But, Game Maker ignores it and uses it as a check anyway. So you can get away with using '=' for checks like if 'life = 100'
 
D

David Berkompas

Guest
Thanks @Rivo7014,

I'm slowly working through GMS2 GML overview, getting the feel for things.

I used to be an embedded code monkey utilizing C (except for my Gameboy Color stint, that was pure asm). My specialty was firmware for HP and later Conexant.

My son wants to write video games, so I'm working with him to learn GMS2. I bought the Humble Bundle a week ago or so, and immediately upgraded from 1.4.

Hoping to learn and eventually contribute here.


Dave
 
Y

Yvalson

Guest
It's good to get in the habit of doing that, since that's the proper way to do it. But, Game Maker ignores it and uses it as a check anyway. So you can get away with using '=' for checks like if 'life = 100'
So will that fix the problem?
 
D

David Berkompas

Guest
To the OP, have you looked at using else statements so the code doesn't have to go through every line?


Dave
 

TheBroman90

Member
Are you sure the directions are exactly 0, 90, 180 and 270? Draw som text for the direction to make sure that isn't the problem.
 
Y

Yvalson

Guest
Are you sure the directions are exactly 0, 90, 180 and 270? Draw som text for the direction to make sure that isn't the problem.
I will do that but doesn't path following along a grid always have 4 directional movement?
 
Y

Yvalson

Guest
Are you sure the directions are exactly 0, 90, 180 and 270? Draw som text for the direction to make sure that isn't the problem.
yupp that was the issue for some reason the direction even on the grid was varying so what I did was check in between

0 and 45 and 316 and 360 for right
46 and 135 for up
136 and 225 for left
and 226 and 315 for down

and it works like a charm now

@Yvalson No, sorry I just say what david said and thought i'd say something haha

@David Berkompas Good luck!
well anyway the problem is fixed now
 
Top