A
Andres Molina
Guest
Hey, im trying to learn GML so i started creating a really basic game. My objective now is to create a moving enemy, make it move 2 seconds to the left, idle 1 sec and 2 seconds to the right, then repeat. This is the thing, ive write this code and what happens is that the object starts teleporting to the left / right every step. I still cant figure out whats wrong. Tell me please what is wrong with it, dont make any code for me, i want to figure out how to do this (i know there should be like 1000+ ways to do it, but maybe im too stupid who knows)
This is my code:
//Movement
if (idle == 1)
{
for (i=0;i<=idle_ms;i+=1) //idle_ms == time in ms to idle (since my room is capped to 60steps/s this equals to 60)
{
if (i==idle_ms) //This executes once, at the end of the for loop
{
idle = 0;
orientation *=-1; //where 1 is right, and -1 is left.
}
}
}
if (idle == 0)
{
for (i=0;i<=move_ms;i+=1)
{
if (orientation == 1)
{
x+=movespd; // movespd = 1. 1 pixel/s.
}
if (orientation == -1)
{
x-=movespd;
}
if (i==move_ms)
{
idle = 1;
}
}
}
the enemy_o create code:
movespd = 1;
move_ms = 0;
idle_ms = 0;
idle = 0;
orientation = 1;
move_s = 2;
idle_s = 1;
move_ms = move_s*60;
idle_ms = idle_s*60;
Thanks!
This is my code:
//Movement
if (idle == 1)
{
for (i=0;i<=idle_ms;i+=1) //idle_ms == time in ms to idle (since my room is capped to 60steps/s this equals to 60)
{
if (i==idle_ms) //This executes once, at the end of the for loop
{
idle = 0;
orientation *=-1; //where 1 is right, and -1 is left.
}
}
}
if (idle == 0)
{
for (i=0;i<=move_ms;i+=1)
{
if (orientation == 1)
{
x+=movespd; // movespd = 1. 1 pixel/s.
}
if (orientation == -1)
{
x-=movespd;
}
if (i==move_ms)
{
idle = 1;
}
}
}
the enemy_o create code:
movespd = 1;
move_ms = 0;
idle_ms = 0;
idle = 0;
orientation = 1;
move_s = 2;
idle_s = 1;
move_ms = move_s*60;
idle_ms = idle_s*60;
Thanks!