Problems with the enemies movements

Please help me,

I have a trouble with the moves of the enemies in my game!!

They are facing right, but when they walk to left, they don't turn to the left and make a "moonwalk".
Also, I can't make they change to stopped sprite when they are stopped and they keep with the walking animation even if they are stopped.


Variables:
hp=100
enemy_speed=2.5

Code:
if(distance_to_object(obj_character)<300 && hp>0){
mp_potential_step(obj_character.x, obj_character.y, enemy_speed, true);
}

if enemy_speed<=0{
enemy_speed=0;{
sprite_index=spr_enemy_stopped;image_speed=0.3}
}


I made a code to the enemy follow my character and this is working. Only the animation of enemy stopped and turned to the left is not working.
 

Nidoking

Member
Well there's no code there that would make an enemy turn to the left. You should put some in there.

There's also no way for enemy_speed to be <= 0. I don't think the speed will ever be negative the way you're using it.
 
Well there's no code there that would make an enemy turn to the left. You should put some in there.

There's also no way for enemy_speed to be <= 0. I don't think the speed will ever be negative the way you're using it.
Right. Thanks, can you help me to create a functional code to make the enemy walks normally please?
 

Pretorg

Member
You could try to check for the difference between the enemy's x and the player's x, something like this
if (x > obj_character.x){
image_xscale = -1;
}else{
image_xscale = 1;
}
With that the enemy would always be facing object character as image_xscale -1 will mirror the sprite on the X axis, but if you don't want the enemy to be always facing the player you could use a variable like moving= 0;
and then
if(distance_to_object(obj_character)<300 && hp>0){
mp_potential_step(obj_character.x, obj_character.y, enemy_speed, true);
moving = 1;
}
if(moving == 1){
if (x > obj_character.x){
image_xscale = -1;
}else{
image_xscale = 1;
}
}
As for your problem with the sprite_index, I am assuming that the enemy_speed variable is at the create event and that you are not changing it anywhere to other values using a state machine if that's the case you are always checking if 2.5 is < 0 which is never going to happen, you should be using the built-in variable speed instead.
I am not entirely sure this would work, haven't really used potential_step so I don't know what goes on with speed, if you want you can check the speed value on the step event using show_debug_message(speed) (I think), it will show you the value on the compile window but for this you'll have to run the game windowed if you want to see it live.

I hope this was helpful, I am not that good at making code on the go, without constantly checking it in game ;)
 
Top