How do I spawn randomly off screen

Get help using Construct 2

Post » Wed Oct 07, 2015 3:33 am

How do I make it so a certain object will spawn at a completely random location off screen, then move towards the player? I can probably figure out the moving part but not the spawning. If I pick a random location completely sometimes it spawns on the screen, and sometimes it spawns so far away it might as well not be there! How do I limit this kind of thing?
B
6
S
1
Posts: 46
Reputation: 492

Post » Wed Oct 07, 2015 9:23 am

One way to do it is to spawn it at the player(or some other on-screen location), then use the "move at angle" action with a random angle to move it off screen in a random direction.
B
10
S
3
G
1
Posts: 14
Reputation: 809

Post » Wed Oct 07, 2015 2:55 pm

hellando wrote:One way to do it is to spawn it at the player(or some other on-screen location), then use the "move at angle" action with a random angle to move it off screen in a random direction.

Eh that kind of works, but theres 2 problem with it:
1) No matter the speed, the spawned object shows up on screen for like a frame, which is noticeable.

2) the spawned object is meant to be destroy when it touched the object its spawning from, i get set variables that toggle when it's spawned so that it isn't destroyed, but if anther one touches the object thats spawning them while one is being spawned, it wont be destroyed, thus creating a bug.

EDIT
I managed to fix that first problem just by moving to different layers
B
6
S
1
Posts: 46
Reputation: 492

Post » Wed Oct 07, 2015 3:23 pm

Ne7herM0St wrote:
hellando wrote:One way to do it is to spawn it at the player(or some other on-screen location), then use the "move at angle" action with a random angle to move it off screen in a random direction.

Eh that kind of works, but theres 2 problem with it:
1) No matter the speed, the spawned object shows up on screen for like a frame, which is noticeable.

2) the spawned object is meant to be destroy when it touched the object its spawning from, i get set variables that toggle when it's spawned so that it isn't destroyed, but if anther one touches the object thats spawning them while one is being spawned, it wont be destroyed, thus creating a bug.

EDIT
I managed to fix that first problem just by moving to different layers



As long as you create it and move it in the same event, it should in a single frame, and it should not do any collision tests until after it has moved. Here is a capx file with an example

also here is another capx file with a small game i made using 2 different methods of spawning objects off-screen
B
10
S
3
G
1
Posts: 14
Reputation: 809


Return to How do I....?

Who is online

Users browsing this forum: unxcellent and 4 guests