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

Spawning off Screen move towards the center[SOLVED]

K

Karrlem

Guest
Hello all, I would like to know how to go about having enemies spawn outside of my room and move towards the center of the room.
 

Bingdom

Googledom
CREATE EVENT:
Code:
x = choose(-random(100), room_width + random(100)); //Outside the left and right side of the room up to 100 pixels
y = choose(-random(100), room_height + random(100));

direction = point_direction(x,y,room_width/2,room_height/2);
speed = 2;
So basically what happens the choose() chooses either of the two values.

point_direction() starts from where enemy is, then points towards the center of the room

speed is used to set the speed of the enemy
 
K

Karrlem

Guest
CREATE EVENT:
Code:
x = choose(-random(100), room_width + random(100)); //Outside the left and right side of the room up to 100 pixels
y = choose(-random(100), room_height + random(100));

direction = point_direction(x,y,room_width/2,room_height/2);
speed = 2;
So basically what happens the choose() chooses either of the two values.

point_direction() starts from where enemy is, then points towards the center of the room

speed is used to set the speed of the enemy
That works perfect! Thank you soo much for the help!
 
K

Karrlem

Guest
CREATE EVENT:
Code:
x = choose(-random(100), room_width + random(100)); //Outside the left and right side of the room up to 100 pixels
y = choose(-random(100), room_height + random(100));

direction = point_direction(x,y,room_width/2,room_height/2);
speed = 2;
So basically what happens the choose() chooses either of the two values.

point_direction() starts from where enemy is, then points towards the center of the room

speed is used to set the speed of the enemy
I only got one question, I realized that it works properly but everything only spawns from the four corners of the screen. Do you know of a fix?
 

Bingdom

Googledom
Sure, here is something that I tested and should work. ;)
Code:
if irandom(1) == 0 {
    y = choose(-random(100), room_height + random(100)); //Come from either top or bottom
    x = random(room_width);
} else {
    x = choose(-random(100), room_width + random(100)); //Come from either left or right
    y = random(room_height);
}
 
K

Karrlem

Guest
Sure, here is something that I tested and should work. ;)
Code:
if irandom(1) == 0 {
    y = choose(-random(100), room_height + random(100)); //Come from either top or bottom
    x = random(room_width);
} else {
    x = choose(-random(100), room_width + random(100)); //Come from either left or right
    y = random(room_height);
}
Works! Thanks again!!
 
Top