How do I Spawn object or enemy

Get help using Construct 2

Post » Wed Sep 21, 2016 10:43 pm

ok here is what i want to do
i want asteroids or enemy to spawn in a minimum range from the player so that way my player wont collide with a spawned object on him and there for die for no good reason XD

could you post capx :D ty
B
28
S
9
G
3
Posts: 136
Reputation: 3,775

Post » Thu Sep 22, 2016 12:14 am

Depends on how you are spawning randomly to begin with. If it is random x, y coordinate, you can add a condition to check the distance of that coordinate to the player. If it is within a certain range, pick a new coordinate, else spawn at that coordinate.
Mistakes were made.
B
52
S
26
G
111
Posts: 1,623
Reputation: 62,667

Post » Thu Sep 22, 2016 1:07 am

can you make a capx cuz im not really a good coder yet haha im really visual tu understand things :D ty tho :D
B
28
S
9
G
3
Posts: 136
Reputation: 3,775

Post » Thu Sep 22, 2016 1:13 am

You can simply use the in-built random range;

Code: Select all
on event
    create [object] at (player.X+random(100,1000)


This will create an object at least 100 to the right of the player, and at most 1000.

Alternatively, for both directions (of course, it's the same for the Y coordinate):
Code: Select all
on event
    create [object] at (player.X+choose(random(100,1000), random(-1000,-100)

The choose() function has no bias, so the two other random functions will have the same chance of happening.

Edit: details on choose() and random() here: https://www.scirra.com/manual/126/system-expressions
B
42
S
14
G
3
Posts: 165
Reputation: 5,115

Post » Thu Sep 22, 2016 10:16 am

syntax error so not working :(
can you make a little capx ?
B
28
S
9
G
3
Posts: 136
Reputation: 3,775

Post » Thu Sep 22, 2016 10:25 pm

Please press F5 to refresh to see where the enemy would spawn. It will never overlap the Player. :D

https://www.dropbox.com/s/zr014tr3p7jb7 ... .capx?dl=0
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Fri Sep 23, 2016 2:37 pm

kiugetski if wish tolearn more this link will provide you with many tutorial

https://www.dropbox.com/sh/eioscti86bpr ... 7YPza?dl=0
B
252
S
39
G
15
Posts: 1,964
Reputation: 40,763


Return to How do I....?

Who is online

Users browsing this forum: 25games, jatin1726 and 30 guests