• 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!

Boomerang like effect

Zapzel-24

Member
I have been working on a flying enemy that swerves back and forth and often times changes its elevation I have to code it the best of my abilities but the sprites themselves just vanish into thin air. It is hard to put it into words so I have a video to give general idea i am trying to aim for.


here is the code I used to attempt this:
Create Event:
Code:
//alarm to change the X axis
alarm[1] = choose (100,150);

//Alarm to change the Y axis
alarm[2] = choose (100,150);
Alarm 1:
Code:
//Change the X axis
if (facing == 1)
{
    x *= -1;
}

if (facing == -1)
{
    x *= -1;
}

//Reset Alarm
alarm[1] = choose (100,150);
Alarm 2:
Code:
//Change Y axis
if (facing == 1)
{
    y *= -1;
}

if (facing == -1)
{
    y *= -1;
}

//Reset Alarm
alarm[2] = choose (100,150);
Step Event:
Code:
if (facing == 1)
{
    x += 1;
}

if (facing == -1)
{
    x -= 1;
}
image_xscale = sign(x);
Draw Event:
Code:
draw_sprite_ext(spr_Enemy,sprite_index,x,y,facing,1,0,c_white,1);
 

NightFrost

Member
Your draw wants a subimage but you are giving it sprite_index. Just give it a -1 unless you're handling animation through code.
 

Zapzel-24

Member
Thank you,that solved my image ,but I'm having trouble getting the enemies to move in a boomerang like fashion like seen in the video.
 

TheouAegis

Member
why are you negating x and y? That will put the enemy outside of the room where you can't see it. Think things through logically.

AAlarm 0 event :
image_xscale *= -1;
alarm[0] = choose(100,150);

Alarm 1 event:
float = choose(-1,1);
alarm[1] = choose(50,75,100,150);

Step Event:
x += image_xscale;
y += float/4;

No draw event
 

NightFrost

Member
Your alarms should be changing the facing value, not x and y. You only have one facing variable as well, you should have one for both x and y. Your step only processes x and does nothing for y. When you set image_xscale, you should take sign of horizontal facing, not x-coordinate. And in your draw you override xscale by giving it facing instead. Once you get that working, your enemies will probably move at 45 degree angles. Set the horizontal speed larger (or vertical smaller) to make them move bit more like in the video.

EDIT: the enemies in the video seem to be using a velocity & acceleration to move around, but concentrate first on getting basic movement done.
 
Top