Collision between two identical objects?

Get help using Construct 2

Post » Tue Apr 24, 2012 6:34 pm

I'm making a breakout style game, and was wondering if there's a way to differentiate in the actions the reference to 'self' and 'other' instances of the same sprite?

Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939

Post » Tue Apr 24, 2012 6:41 pm

You can use Pick nth instance in the System object to pick by index the objects involved in the collision event - just add the picking as a subevent and you should be good to go.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Tue Apr 24, 2012 8:28 pm

Ah - so - 1st would be 'self', 2nd etc would be 'other', if I understand correctly?
Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939

Post » Tue Apr 24, 2012 9:09 pm

B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Tue Apr 24, 2012 11:28 pm


Thanks, that helps a lot,I had a look at the attached, and I will go with families for now.

I was just wondering if there was something simple that I was overlooking like :


Sprite1 on Collision with Sprite1

Sprite1(Self) Score+=1

Sprite1(Other) Destroy



JohnnySix2012-04-24 23:30:54
Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939

Post » Wed Aug 15, 2012 11:50 pm

Hmm, managed to dig this topic back out haha.

I did a quick demo for a friend tonight to show him how quick it is to concept stuff in Construct2. The actual game including sprites and basic physics was up and running in 20 minutes, but then came the hard part :

http://www.johnnysix.net/games/Flap/

If you try the demo you'll see what the issue is. Because I can't use the velocity component of a physics object directly, nor test for "self.variable" or "other.variable" when testing collision between two entities of the same type, everything goes a bit haywire.

Link to CAPX file :
http://www.johnnysix.net/games/Flap/flap.capx

Click, drag and release anywhere to launch le oiseau.JohnnySix2012-08-15 23:51:39
Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939

Post » Fri Nov 02, 2012 7:53 am

Crap. I posted another topic for this without digging longer. But seriously is there a way to differentiate between the 2 instances involved in the collision?
B
7
Posts: 38
Reputation: 683

Post » Mon May 13, 2013 9:45 pm

I have searched everywhere for a simple solution for this, and is actually quite surprised that it seems overlooked; or did I just miss that part of the manual?

Self and other is a neat solution in several other systems, and perfect for standard collisions and so on.

Edit: Thanks to the one that mentioned pick nth instance - https://www.scirra.com/manual/124/system-conditions
Ill try this and see how it works.crawly2013-05-13 21:48:52
B
4
Posts: 7
Reputation: 389

Post » Mon May 13, 2013 10:00 pm

Ok, still not getting it...

I got identical blue squares floating around in a random way. If two collides I want to check if they are the same size, and if they are increase both sizes by some amount. Different sized squares should merely bounce off eachother.

What I want to do is (in a basic kind of way):

If square collides with square
AND
self.height = other.height
THEN
self.height=self.height*1.1; self.width=self.width*1.1
other.height=other.height*1.1; other.width=other.width*1.1crawly2013-05-13 22:01:07
B
4
Posts: 7
Reputation: 389

Post » Mon May 13, 2013 10:33 pm

Ok, I found a (not so) quick and dirty event based solution but i'm not sure it's the best one. Anyway - it works!

I have my blue square objects which I named "R". I also made a controller object named "C", which is placed off screen. C have two instance variables named "first" and "second".

* R - on collision with R
*     System - Pick R instance 1 (make a sub-event, system and "pick nth instance"
The action part of the sub-event is "C" set "first" to R.height (height of R gets stored in the "first" variable of "C")
* Make another sub-event to the first collision event but this time pick instance "1" and store the height in the variable named "second".
* Create yet another sub-event (from the collision event), choose "C" compare instance variables and check if "first" and "second" are equal.
* Create two new sub-event from the comparison sub-event (so that it's a sub-sub-event when viewed from the initial event); choose "System" and pick nth instance again (first instance "0" and then instance "1"). Adjust their sizes accordingly (or whatever you want to do).

It sure gets more complex to explain then it looks on the screen.

You basically have the first collision event to catch the actual collision event. Underneath this one you use "pick nth" to store the height (or something else) in a controller object, for the two objects involved (0 and 1 for pick nth).
Last you compare these figures, but put this comparison-event under the initial even to avoid it getting checked outside actual collisions.

So it works. it's just a bit clumsy.
B
4
Posts: 7
Reputation: 389

Next

Return to How do I....?

Who is online

Users browsing this forum: Artpunk and 15 guests