G
GalaxyKitten
Guest
Hi there, I currently have an enemy that sticks to walls. When a corner approaches, it will change its degree to 90 degrees to match that.
Imagine a box, the enemy will crawl all around it, up the walls, upside down, nice and good! But when it reaches a slope, it goes crazy because it tries to flip 90 degrees on a 45 degree angle for example. What would be the best way for it to just match the slope or angle its currently on?
Thank you!
Imagine a box, the enemy will crawl all around it, up the walls, upside down, nice and good! But when it reaches a slope, it goes crazy because it tries to flip 90 degrees on a 45 degree angle for example. What would be the best way for it to just match the slope or angle its currently on?
Code:
event_inherited();
if(global.gamePaused || frozen > 0)
{
image_speed = 0;
exit;
}
else
{
image_speed = 0.3;
}
var b = true;
if(place_meeting(x + lengthdir_x(sign(spd), dir), y + lengthdir_y(sign(spd), dir), obj_Tile))
{
dir = (dir + sign(spd) * 90) mod 360;
b = false;
}
else if(fpixel <= 0 && !place_meeting(x + dcos(dir - 90), y - dsin(dir - 90), obj_Tile))
{
dir = (dir - sign(spd) * 90) mod 360;
fpixel = 1;
}
if(b)
{
x += lengthdir_x(spd, dir);
y += lengthdir_y(spd, dir);
fpixel -= abs(spd);
}
var vx = lengthdir_x(0.5, dir-90),
vy = lengthdir_y(0.5, dir-90);
if(!place_collide(vx,0))
{
x += vx;
}
if(!place_collide(0,vy))
{
y += vy;
}
animDir = dir;
var angleDiff = angle_difference(animDir,imgAng);
imgAng += min(11.25,abs(angleDiff))*sign(angleDiff);