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
http://www.twitch.tv/kiugetski
https://discord.gg/55R9Gbs

feel free to contact me of follow me :) i can give some advice
B
37
S
11
G
4
Posts: 161
Reputation: 4,812

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
60
S
30
G
133
Posts: 1,948
Reputation: 74,873

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
http://www.twitch.tv/kiugetski
https://discord.gg/55R9Gbs

feel free to contact me of follow me :) i can give some advice
B
37
S
11
G
4
Posts: 161
Reputation: 4,812

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
ImageImage

Take a look at my itch.io games
B
45
S
14
G
3
Posts: 167
Reputation: 5,204

Post » Thu Sep 22, 2016 10:16 am

syntax error so not working :(
can you make a little capx ?
http://www.twitch.tv/kiugetski
https://discord.gg/55R9Gbs

feel free to contact me of follow me :) i can give some advice
B
37
S
11
G
4
Posts: 161
Reputation: 4,812

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
267
S
51
G
16
Posts: 2,039
Reputation: 43,944


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests