[Solved] How to get UID of collisioned objects?

This forum is currently in read-only mode.
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • My goal is to get UID of collision objects (pair).

    I found that there are two system condition "On collision(advance)" and "On overlap(advance)" can pick two objects.

    I tried "On collision(advance)" but didn't work. "On overlap(advance)" can get object pair sometimes.

    Here is my test file.

    http://dl.dropbox.com/u/5779181/collision_pair.zip

    Thanks.

  • Your code here does work properly:

    + System: On collision between Green (Pick) and Blue (Pick)
        -> Output: Add 1 to 'hitCnt'
        -> Output: Set text to Output.Value('hitCnt') & " : (" & Green.UID & "," & Blue.UID & ")"[/code:3gvj8dlq]
    
    The reason that it's not triggering a collision consistently is that the Ball Behavior is performing it's own collision check and bouncing the balls away from each other before the sprites themselves can overlap.  On Collision checks for overlap between two sprites, so if they're never actually overlapping then On Collision won't trigger.
    
    Turn off Solid attribute for the balls and you will see that it's working and the UIDs are being picked properly.
    
    The reason that it works [i]sometimes[/i] is that it's possible that timedelta is allowing the balls to move slightly closer to each other than they normally would before being bounced away, and on the next frame they are still overlapping and trigger On Collision.
    
    You can get around this collision problem in a few different ways:
    
    1. Don't use Ball Behavior.  Physics Behavior can register "collisions" without having sprites overlap, and as a bonus you will get more accurate angle changes when objects collide.
    
    2. Do use Ball Behavior, but try one of the following:
    [ul]
    [li] Turn off Solid for the ball sprites and code in your own bouncing events to change the angles of the balls when they hit each other.[/li]
    [li] Add a separate, non-solid detector object to the ball (using Containers) that is slightly bigger than the ball.  Use that for your On Collision event so that you can pick up the UID of the object the ball is colliding with.  Like so: [/li][/ul]
    <img src="http://i52.tinypic.com/20561lh.png">
    
    Hope this helps.
  • Method 2 is a good solution , Thanks.

    But I still has some questions,

    1. about collision detecting of Ball behavior

    [quote:2f52r2sy]it's not triggering a collision consistently is that the Ball Behavior is performing it's own collision check and bouncing the balls away from each other before the sprites

    I can use sprite's "On collision between" event, like that

    + ball: On collision between ball and ball
    -> output: Add 1 to 'hitCnt'
    -> output: Append text output.Value('hitCnt') & " : ( " & ball.UID & " , " & ball.UID & " ) " & newline[/code:2f52r2sy]
    It's work (but not enought for my goal). Ball's collision can be detected in this case.
    
    2. how to get second object(objectB) in "is Overlapping (advance)" 
    [code:2f52r2sy]+ System: Green (Pick) and Blue (Pick) are overlapping[/code:2f52r2sy]
    In "is Overlapping (advance)", it can pick two object( objectA= Green, objectB = Blue). 
    I can't identify objectA and objectB in action if I use the same object in event like that
    [code:2f52r2sy]+ System: ball (Pick) and ball (Pick) are overlapping[/code:2f52r2sy]( objectA= ball, objectB = ball)
    
    Here is my test cap file
    [url=http://dl.dropbox.com/u/5779181/collision_pair.zip]http://dl.dropbox.com/u/5779181/collision_pair.zip[/url]
  • how to get second object(objectB) in "is Overlapping (advance)"

    + System: Green (Pick) and Blue (Pick) are overlapping[/code:3juau27c]
    In "is Overlapping (advance)", it can pick two object( objectA= Green, objectB = Blue). 
    I can't identify objectA and objectB in action if I use the same object in event like that
    [code:3juau27c]+ System: ball (Pick) and ball (Pick) are overlapping[/code:3juau27c]( objectA= ball, objectB = ball)
    
    Here is my test cap file
    [url=http://dl.dropbox.com/u/5779181/collision_pair.zip]http://dl.dropbox.com/u/5779181/collision_pair.zip[/url]
    

    If you want to detect collision between two objects, and get the UID of each of those objects separately without using the Family Trick, then you can do so with this method:

    http://dl.dropbox.com/u/529356/Construc ... orting.cap

    It's a little more complicated, but it doesn't use families or advanced overlapping.

    It does use some global and private variables to keep track of which objects are being sorted during collision though. Anyway, I commented it so have a look, and if you have any questions feel free to post them.

    Also... there seems to be a bit of a bug where multiple collisions are registering at once for the same two objects colliding. You could add some events to make sure that only one collision is registered to compensate for that. BUT it is getting the UIDs of either colliding object correctly.

    Also, the way it's set up right now, the object with the lowest UID will always show up first in the output list. This is due to sub-event #9, which assigns the order in a loop based on UID ascending. You can change the way the balls are selected to make that more random if you need to.

    Anyway, hope this helps.

  • I think you could also try "pick closest", based on the dimensions of the room.

    Like:

    +sprite on collision with sprite

    ->sprite pick closest to 0x, 0y-- add uid to list

    ->sprite pick closest to 640x, 480y-- add uid to list

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you.

    Method 2 (add a detector sprite) looks better for detecting multi-pairs. (I'm not sure because of Family Trick.)

    Hope there is a more directly way of the advance version.

  • Hi,

    I test "System - Is overlaping (advance)" for multi-pair overlaping. (#4)

    http://dl.dropbox.com/u/5779181/collisi ... _test2.zip

    Unfortunately, it can detect "one" pair only.

    There is an interesting way to get UID of overlaping objects.

    In #5 & #6,

    + Blue: Blue overlaps Green
    + System: For each Green
    -> output: Add 1 to 'hitCnt'
    -> output: Append text output.Value('hitCnt') & " : ( " & Blue.UID & " , " & Green.UID & " )" &newline
    [/code:1s4ffk1g]
    
    I put the same object into family "Blue" and "Green"(family trick   ).
  • Hello! I have met a problem of overlapping, too.

    Here is my problem ...

    I have a sprite--Poker , there are five instances of Poker and they stand by a line , some part of one instance is overlapping to another . There is an event: if I touch one instance, it should move to another place. But when I touch the area which is just the area where the two Pokers overlap, the two cards both move. I just want the Poker on the top move.

  • MelonGuns

    There has a condition which could pick the top one instance.

    scirra.com/manual/131/common-conditions

  • rexrainbow

    Thank you! It really works!

    I just wrongly mistook used this method before...I was thinking it would choose the topest instance on the layout!

    Thank you again!

  • Hi,

    I am working on a project in which I have 8 characters.

    I want to check which character hits which character with which skill. According to that i calculate the damage.

    https://drive.google.com/open?id=0BwybgTYLYob0TzE1aEdfZzhsVzQ

    Is there a way to check which character hits whom and then apply a common formula which replaces the variables according to the 2 interacting characters.

    Because what I am doing right now will take up around 600 events just for the attacking of each character. As they have 5 skills right now. In some time I am planning to have around 15 skills per character. So you can imagine how many events will go in this and useless resource consumption.

    If there are any tips, please let me know. Thanks in advance!!

  • udain1286

    Hi,

    I am working on a project in which I have 8 characters.

    I want to check which character hits which character with which skill. According to that i calculate the damage.

    https://drive.google.com/open?id=0BwybgTYLYob0TzE1aEdfZzhsVzQ

    Is there a way to check which character hits whom and then apply a common formula which replaces the variables according to the 2 interacting characters.

    Because what I am doing right now will take up around 600 events just for the attacking of each character. As they have 5 skills right now. In some time I am planning to have around 15 skills per character. So you can imagine how many events will go in this and useless resource consumption.

    If there are any tips, please let me know. Thanks in advance!!

    Are you sure you've posted this in the right section?

    This is the - now retired - Construct Classic section.

  • i have posted this in forums under how do I? but i saw this post and thought that this is a similar problem and as they know the solution maybe they could help me. that is why i posted it here too.

    but yeah i did not check if this was for construct 1 or 2 and in the archive section.

    thanks for the heads up.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)