How to get UID of two Overlapping objects ?

Get help using Construct 2

Post » Sat Aug 06, 2016 10:07 am

Hello here is my problem :
I have 10 instances of the same sprite,
I want that when one instance is overlapping another instance, one of the two instances stop its movement.

But when I put the condition : when sprite is overlapping sprite -> stop the movement
The problem is that the two instances stop their movement whereas I want only one of the 2 to stop its movement.

So is there a way to get the UID of the two Overlapping objects and to do action separately with the two object ?

Thanks for the answers
B
13
S
3
Posts: 32
Reputation: 847

Post » Sat Aug 06, 2016 10:44 am

Use System|Pick Sprite Instance nth as a sub-event under the collision/overlap event.
As a subevent after a collsion event there are only two instance to pick. The two instances that are overlap.
It would look like this:

Sprite| Is overlapping Sprite
...System|Pick Sprite Instance 0 -> Do something with the Sprite with the lower UID than the other.

If you use 1 then you pick the Instance with the higher UID from both.

To pick the UID from each one do this.

Sprite| Is overlapping Sprite -> System| Set myUID1 to Sprite.UID
...System|Pick Sprite Instance 1 -> System| Set myUID2 to Sprite.UID
B
24
S
3
G
1
Posts: 454
Reputation: 2,171

Post » Sat Aug 06, 2016 11:48 am

Really thanks Asmodean for the help, Here is a link to a capx that illustrates how to pick seperately two instances that are in collision done with your help :

https://www.dropbox.com/s/rg7bpuodhq6e1 ... .capx?dl=0

It's the same way to select instances with collision and overlapping, so I thought it was more interesting for me to put an example based on collision and physics for people to see how it works.

in this capx, 2 sprites have physics gravity on it, when there is a collision, one sprite will jump and the other one will see its width increase, download the project with the link you will understand, if questions post it.
B
13
S
3
Posts: 32
Reputation: 847

Post » Sat Aug 06, 2016 11:59 am

That's a really nice example. Even after a year with Construct it amazed me how little code it take to make such a example. :)
Nice work!
B
24
S
3
G
1
Posts: 454
Reputation: 2,171

Post » Sat Aug 06, 2016 12:07 pm

Yes it doesn't take a lot of code to do that, that's nice ! Thanks :)
B
13
S
3
Posts: 32
Reputation: 847


Return to How do I....?

Who is online

Users browsing this forum: Felipiwi and 28 guests