SOLVED Problem with wandering movement?

Rexzqy

Member
So i am making a wandering movement for enemy. Its wandering properly, but i want it to go into a reverse direction when its about to go into a wall. So below is my code:

if(place_meeting(x+moveX1,y,obj_e_wall))
{
moveX1 = lengthdir_x(spd,-my_dir);
}
if(place_meeting(x,y+moveY1,obj_e_wall))
{
moveY1 = lengthdir_y(spd,-my_dir);
}


x += moveX1;
y += moveY1;

However the enemy can go through walls when they are wandering. Any help is greatly appreciated!!!
 

Yal

šŸ§ *penguin noises*
GMC Elder
Your directional calculation is all wrong, you should use my_dir + 180 instead of -my_dir if you want to reverse a direction... -0 and +0 have the same value, so the horizontal direction won't mirror. Also, don't forget to actually update my_dir by adding the appropriate value to it...
 
Top