check overlap between same object type

For questions about using Classic.

Post » Mon Jan 12, 2009 9:35 pm

i'm trying to achieve the following scenario: a number of circles are drifting towards the center of the screen. if any of the circles overlaps another circle, they get pushed away from one another (so that no two circles overlap). the effect should (in the end) be similar to this.

i am having a hard time getting construct to pick the right objects and generally do as it is told. i have almost gotten it to work, but the event sheet looks horribly wrong; some 'pick by evaluate' conditions appear to not evaluate unless preposed with a 'for each' loop & other such nuisance, and the entire thing runs at 7fps when started.

maybe somebody already did something like that (overlapping of same object type) and has the clever solution, or would like to point out the principal error in my approach?
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Tue Jan 13, 2009 6:33 am

The only propely working solution is to apply two families to same object type, and make conditions where "Family A" overlaps with "Family B" to distanguish the different instances. There have been discussion about this before, [url:19a6mneu]http://www.scirra.com/phpBB3/viewtopic.php?f=3&t=1541&st=0&sk=t&sd=a&start=20[/url:19a6mneu], [url:19a6mneu]http://www.scirra.com/phpBB3/viewtopic.php?f=16&t=1667[/url:19a6mneu] and [url:19a6mneu]http://www.scirra.com/phpBB3/viewtopic.php?f=17&t=1740&p=12449[/url:19a6mneu]
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Tue Jan 13, 2009 12:13 pm

I don't know how many objects you're planning on having, but keep in mind that checking for collisions against the same object is essentially the same as looping through every object every time it has to do a collision check, so with 100 objects, it'll actually be checking collisions 10,000 times. I just wanted to point that out since it could become a bottleneck for performance in your game.
B
2
S
1
G
5
Posts: 59
Reputation: 1,518

Post » Tue Jan 13, 2009 5:15 pm

Doesn't construct have to loop though objects anyway, even if the colliding objects weren't same type?

Well, it's internal loop so it's probably a lot faster...
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Tue Jan 13, 2009 10:03 pm

Yeah it does, but performing a collision check is a pretty expensive operation, so it soon adds up in a large loop like that.
B
2
S
1
G
5
Posts: 59
Reputation: 1,518

Post » Tue Jan 13, 2009 10:30 pm

thank you very much for these important hints!
seems i have a few pages of forum material to catch up with :)

p.s. you rock! :)
B
2
S
2
G
4
Posts: 171
Reputation: 1,792


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests