Help with two objects fusing/breaking apart

Post your own tutorials, guides and demos.

Post » Wed Apr 08, 2009 6:17 pm

I did the art for a friend of mine's game, but this is my first try using construct, after watching him fiddle around.

Most of the included things are for aesthetics, like the fire-mosquito and sunlight. The dirtbunnies (black dots, green eyes) are the gameplay element I need help with. They float around alright, but what I plan to have them do is all start out small. I created a "Size" Private variable for this, which they all start out on '1'. Start of layout, they float around randomly. I want the Size 1 bunnies to collide, and become Size 2 bunnies. Then as the bunnies collide I want a size (x) and a size (y) to become a Size (x+y), but if a Size (x if x>1) and a Size (x if x>1) collide, they just bounce off each other. I've tried a few things, all ending in failure.

Example if my above wording is too confusing:

Two Size 1 bunnies collide, they become a size 2 bunny.

A Size 2 and a Size 1 bunny collide, they become a Size 3 bunny.

A Size 3 and a Size 2 bunny collide, they become a Size 5 bunny, and so on...

Two bunnies bigger than Size 1 but of the same Size collide, they bounce off each other.



Each increase in 'Size' should increase the bunnies size (height and width) by around 6 units.
I intend to later on add in some sort of weapon (time detonated bomb?/chain-strike weapon?)
that will split any affected bunnies in half (aka Asteroids effect).

Thanks for any help! Here's the cap.
http://dl.getdropbox.com/u/676998/DustB ... hetics.cap
B
2
G
3
Posts: 17
Reputation: 884

Post » Wed Apr 08, 2009 9:22 pm

to check for collision between two instances of the same object, you would need to put that object into 2 different families (e.g. red and green). you can then use a condition like 'red: on collision with green' and follow that up with subevents managing your behavior:
[code:1j1tg4ri]+ red: on collision with green
+ green('size') is equal to red('size')
+ green('size') is greater than 1
> bounce
+ green('size') is equal to 1
> merge
+ green('size') is not equal to red('size')
> merge[/code:1j1tg4ri]
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Thu Apr 09, 2009 12:01 am

I've been wondering about collisions between different instances of the same sprite! The family approach sounds great. :)

But in this case, I tried the approach using the families, and it mostly worked, but crashed sometimes and I couldn't figure out why.

Then I tried a horrible approach that *didn't* use families, just to see if it was possible. This worked without crashing, but sometimes created enormous beasts due to inherent flaws in the method.

Collision between the dust bunny sprites was always unreliable: sometimes it'd work, sometimes it'd ignore the collision. This happened in all circumstances: family or sprite collision, 'collision' or 'overlapping'. I'm still puzzled about that one.

I might go try this in a minimal setting, to see if I can reproduce the crashes (or better yet, create a working solution). Here's the cap, if anyone's curious.

http://dl.getdropbox.com/u/906550/assist.cap

PS: Great sunlight!
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Thu Apr 09, 2009 12:40 am

Okay, so...

Here's a working cap:

http://dl.getdropbox.com/u/906550/assist-2.cap

(Not quite how you described it, but should be easy to modify.)

Here's how the principle looks in a minimalist setting.

http://dl.getdropbox.com/u/906550/Test2.cap

It seems there's a bug in families: 'on collision' between families works fine, but 'on overlapping' sometimes causes a crash. I'll submit this to the tracker.

Collision detection between dust bunnies still seems weird in your cap, but it's okay in the minimalist one. Baffling.
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Thu Apr 09, 2009 3:43 am

Perhaps it would be intelligent to use a second sprite by bounding box instead of by pixel collision tied to the dirt bunny.
B
2
G
3
Posts: 17
Reputation: 884

Post » Thu Apr 09, 2009 6:02 am

That does work:

http://dl.getdropbox.com/u/906550/assist-3.cap

But it works even if you make the bounding box sprite exactly the same as the original dirt bunny sprite and use per-pixel collision.

So the per-pixel collision isn't the problem.

Maybe a bug?
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Thu Apr 09, 2009 10:24 pm

Erm. That is annoying. Oh well.
B
2
G
3
Posts: 17
Reputation: 884


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 1 guest