• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Please Help With Enemy Sprites

K

King Gryzz

Guest
Hello. I am having trouble with figuring out how to make my enemy sprites look right if they are going right etc. I am using Shaun Spaulding's code as a base for my sprites and when I use the dir variable to see whether it looks left or right it just spazzes out. Please help.
Code:
Create event
///Stats
dir = -1;
image_speed = 0.5;
gravsp = 0.5
msp = 6
vsp = 0
hsp = 0
jsp = 11
Code:
Step Event for movement

///Movement

hsp = dir * msp
vsp += gravsp

//Horiz
if (place_meeting(x+hsp,y,Obj_Solid))
{
    while(!place_meeting(x+sign(hsp),y,Obj_Solid))
    {
        x += sign(hsp);
    }
    hsp = 0
}

if (place_meeting(x+hsp,y,Obj_Wall))
{
    while(!place_meeting(x+sign(hsp),y,Obj_Wall))
    {
        x += sign(hsp);
    }
    hsp = 0
    dir *= -1
}

if (place_meeting(x+hsp,y,Obj_EWall))
{
    while(!place_meeting(x+sign(hsp),y,Obj_EWall))
    {
        x += sign(hsp);
    }
    hsp = 0
    dir *= -1
}

//Vert
if (place_meeting(x,y+vsp,Obj_Solid))
{
    while(!place_meeting(x,y+sign(vsp),Obj_Solid))
    {
        y += sign(vsp);
    }
    vsp = 0
}

if (place_meeting(x,y+vsp,Obj_Wall))
{
    while(!place_meeting(x,y+sign(vsp),Obj_Wall))
    {
        y += sign(vsp);
    }
    vsp = 0
}

if (place_meeting(x,y+vsp,Obj_EWall))
{
    while(!place_meeting(x,y+sign(vsp),Obj_EWall))
    {
        y += sign(vsp);
    }
    vsp = 0
}

x += hsp;
y += vsp;

x=clamp(x, 0, room_width);
y=clamp(y, 0, room_height);
 

BLang

Member
Can you show the code where you set the sprites? Nothing really seems wrong with this at first glance.
 
K

King Gryzz

Guest
Can you show the code where you set the sprites? Nothing really seems wrong with this at first glance.
this is the code I used to make the enemy sprites turn left/right
Code:
if (dir = -6) image_xscale = 1
else
{
image_xscale =-1
}
 

hogwater

Member
Why dir = -6? You only need to check if hspeed or equivalent is negative or positive. Which way does your actual sprite image face?
 
Top