Collision detection for instances of same object

Get help using Construct 2

Post » Mon Dec 24, 2012 7:11 pm

I'm using the DragDrop behavior, combined with Is Overlapping event to manipulate sprites. But Construct 2 does not seem to detect collision between instances of the same object type. I have looked through the forum and tutorials that work with UID and IID, but none of these are exposed in the event dialog for me to key off. I also looked at Families but not seeing how that would help here.

I have no problems with this when dealing with instances of two different object types though.
B
3
Posts: 2
Reputation: 279

Post » Tue Dec 25, 2012 4:49 am

Well I never tried to same collision and if that is not working for you; you can try this. Create an invisible sprite over your object, pin it. Then compare ObjectX to ObjectY.
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Tue Dec 25, 2012 5:09 am

Generally you need to pick from the objects already in the sol, filter them if you will.
There are a few conditions that can work as sub events, such as spites pick top most, or pick closest.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Fri Dec 28, 2012 6:46 pm

Thank you for this suggestion jayderyu. It is the solution I picked, and this is how I went about it.

I have two different sprite objects based on the same image. I make one invisible. When I create a new instance of the visible object, I also create an instance of the invisible counterpart and pin it to the visible sibling. I set the z-order of the invisible instance to bottom so the visible instance is always pickable. I added an 'siblingId' instance variable to the invisible object on which I set the UID of the visible instance.

On the drop event of the visible instance, I check that it's UID is not the same as the stored ID of the receiving invisible instance, and this prevents false positive trigger of the visible instance colliding with its own invisible sibling.

To properly clean up the invisible instance when the visible sibling is deleted, I set up an On Destroy system event for the visible object, and do a for each loop on the invisible objects, and destroy the one whose instance variable matches the UID of the just deleted visible instance.

FWIW, I also tried the container approach, but the collision detection wasn't consistent. I might explore that a bit more at a later time.
B
3
Posts: 2
Reputation: 279

Post » Fri Jul 26, 2013 1:33 pm

I cant get this to work. i, trying to get eqch tile placed to check cpllisions on itself to see if it is the top most tile. if so set the animation frame to the top tile frame.   Im trying to use to use a container to create the duplicate sprite and am having odd results. Each tile sprite successfully creates a duplicate and pins it to its location. But when checking collisions between tile and tile duplicates at offsets , it just seems like it randomly sets tiles to "top tile" even if they haven't collided.
B
32
S
4
Posts: 405
Reputation: 3,219


Return to How do I....?

Who is online

Users browsing this forum: flemmig, Jarnopa, semaso, Skebab and 12 guests