[FIXED] How do I find overlaping objects

Just started using Construct 2? Post your questions here

Post » Fri Sep 04, 2015 5:52 pm

Hello everyone,
I am currently struggling with the fact that I can't operate on 2 different instance of the same object, inside a unique event.Here am trying to find an overlaping instance "player" set with a unique ID, and then destroy it. But I also have this same object (which has ID=0) inside the overlaping sprite, and this one I can't destroy.
"EtreAnime" is a sprite pinned to "player', it also has the same unique ID and is in the same container.

Am kinda lost here guys, do you know what i am doing badly ? Tryed many things but "is overlapping" just doesnt detect my other player

Thanks a lot,
Cheers,
Mael
Last edited by Khelben on Mon Sep 07, 2015 11:00 am, edited 2 times in total.
B
7
S
1
Posts: 29
Reputation: 481

Post » Sat Sep 05, 2015 12:03 am

Hm, to find a specific UID you use the event in the cog, for each. Select the object types to loop through, and you'll loop through each of that type. Then a sub event from that event, using the cog again, but this time choose compare two values. For the first value do sprite.UID then your comparison greater than, less than, and then your target value.. In that sub event destroy the sprite...

Compare two values is very useful. You can use it for accessing dictionary keys with a specific value... Checking distance... all kinds of stuff.
B
7
S
2
Posts: 92
Reputation: 663

Post » Sat Sep 05, 2015 12:29 am

HI, thanks for the advice but I need to pick an object here. One that collide with my detection sprite (which is a circle around the player).
If I "for each" all the player, it still doesn't find out which one is collinding my circle... Which is weird ! I also say to him not to pick the one with id=0 cause it's the player himeself (gamepad 0)
B
7
S
1
Posts: 29
Reputation: 481

Post » Sat Sep 05, 2015 1:33 am

I'm not sure I can help. Really need to see what's going on... too bad you couldn't post images yet, but you need certain reps to do that..

Maybe if you explained it in clearer English.

You have a player instantiated, and another object of the same type, just copy and pasted? And you have a circle that comes up around your player, and you want to test which enemies are in the circle? Find one enemy that's inside the circle?

Attach an instance variables to your enemies. A Boolean set to false, called isInsidePlayerSight. Then add an event, every tick. Then add another condition, click the type your testing to overlap, and choose is overlapping another object, or oncollision with another object.. Click the circle.. then in the event click the object, set boolean value, turn isInsidePlayerSight to true... Then make a new event foreach of enemy. On the same event add a new condition choose enemy object, then find "is boolean instance variable set".. in that event do what you need to do to each enemy inside that circle.
B
7
S
2
Posts: 92
Reputation: 663

Post » Sat Sep 05, 2015 1:38 am

The only problem is if you're doing it against two players of the same type you'll have problems, because your player will always be inside the circle. This is why I would use separate sprites for player 1 and player 2, even if they look the same, you'll save yourself a lot of headache by separating their events and data..
B
7
S
2
Posts: 92
Reputation: 663

Post » Sat Sep 05, 2015 1:41 am

If it is two players of the same type just attach another condition to the loop. A second for each loop that says foreach player if uid not = to the uid of the one you want to not destroy... Still, I can't see what you're doing.

If you have two players that look the same, don't cut and paste, make two sprites, but for enemies it doesn't really matter. Should make your coding easier..
B
7
S
2
Posts: 92
Reputation: 663

Post » Mon Sep 07, 2015 11:00 am

Hi Jeremy,
Thanks a lot for your help ! You have well draw my problem.
It made me search elsewhere and I found that the problem was caused by the fact that my detection circle around a player is in the same container that this one.
So when I tell him to find "players" in collision, it doesn't want anything else than its instance.
It's fixed !
Thanks a lot !
B
7
S
1
Posts: 29
Reputation: 481


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests