[SOLVED] Spawn objects only in a sprite collision area?

Get help using Construct 2

Post » Sun Jun 14, 2015 9:09 pm

Hi C2 developers!

I tried in many ways to spawn objects only in a sprite collision area, but still didn't get.

Now I'm using the code below, but the objects still are generated outside the collision polygon.

System create objects:

X: random(Sprite.X-Sprite.Width/2,Sprite.X+Sprite.Width/2)
Y: random(Sprite.Y-Sprite.Height/2,Sprite.Y+Sprite.Height/2)

Object isn't overlapping Sprite, then Object Destroy

Does anyone have a better solution to solve this?

Thanks in advance the attention and collaboration of all. ^^

SOLVED BY @MadSpy! Link of CAPX example below:

https://www.dropbox.com/s/a2l4zbk7sfqk9 ... .capx?dl=0
Last edited by lukezero on Tue Jun 16, 2015 1:59 pm, edited 1 time in total.
B
39
S
9
G
3
Posts: 261
Reputation: 4,377

Post » Mon Jun 15, 2015 6:52 pm

If that Sprite is a Square then you should create object at:

X: random(Sprite.Width) + Sprite.X
Y: random(Sprite.Height) + Sprite.Y

However, if that Sprite is a circle or any other shape, you will need to do the same (as above) but also need to destroy (as you have already) those objects that do not fall under the collision polygon within that squared border of the Sprite.

X If overlapping with Sprite: then Destroy.
B
11
S
3
Posts: 113
Reputation: 1,115

Post » Mon Jun 15, 2015 8:05 pm

Thanks, @Hasan999. :D

Both objects (the spawned and the spawner) aren't Squares.

Only one sprite is spawned in the object.

I tried your code here but most of the generated objects are destroyed immediately. :(
B
39
S
9
G
3
Posts: 261
Reputation: 4,377

Post » Mon Jun 15, 2015 9:04 pm

OK I think I made a mistake. It should be:

X: random(Sprite.Width) + Sprite.X - Sprite.Width/2
Y: random(Sprite.Height) + Sprite.Y - Sprite.Height/2

Then also change the overlapping statement under this condition:

On Object Created:
X If overlapping with Sprite: then Destroy.

Let me know the result..
If it still doesn't work as expected, upload your capx and I'll trouble-shoot.
B
11
S
3
Posts: 113
Reputation: 1,115

Post » Tue Jun 16, 2015 12:35 am

Thanks one more time for your collaboration, @Hasan999. :D

Unfortunately these instructions didn't work as expected.

The objects still are created without the limitations of the object collision area. :(
B
39
S
9
G
3
Posts: 261
Reputation: 4,377

Post » Tue Jun 16, 2015 12:54 am

Check for distance from origin (assuming the area is circular)
B
67
S
26
G
11
Posts: 673
Reputation: 11,557

Post » Tue Jun 16, 2015 1:09 am

that works

Edit: update with bord adjust and irregular collision box
Last edited by MadSpy on Tue Jun 16, 2015 1:33 am, edited 1 time in total.
Image Image
B
27
S
16
G
153
Posts: 887
Reputation: 79,702

Post » Tue Jun 16, 2015 1:19 am

Hmm, not for me it spawns over border.
I correct it:
https://dl.dropboxusercontent.com/u/95601836/spawn.capx
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
11
S
4
G
1
Posts: 158
Reputation: 1,328

Post » Tue Jun 16, 2015 1:24 am

Thanks for your help, @Elliot and @deathangel1479. :D

I made a small adjustment to your instructions, @deathangel1479, but yet not worked.

Thus the objects are infinitely generated continuously.
B
39
S
9
G
3
Posts: 261
Reputation: 4,377

Post » Tue Jun 16, 2015 1:26 am

I'll try these instructions now, @MadSpy and @deathangel1479.

Thanks a lot! :D
B
39
S
9
G
3
Posts: 261
Reputation: 4,377

Next

Return to How do I....?

Who is online

Users browsing this forum: Rable and 6 guests