How do I choose only one object when is overlapping ?

0 favourites
  • 12 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I developed my own engine to handle the bounce of a ball on walls using vectors but I have a problem with the collision detection function of construct2 is overlapping.

    When my ball touches two vectors at the same time (the corners of a rectangle of vectors for example) my engine receives two vectors and it sucks shit.

    Is there a way to tell the is overlapping function to choose only one of the vectors?

    Ty !

  • Which one?

  • In "Is overlapping" event add a sub-event - "For each vector" or any of the "System->Pick" events.

    You can also check how many vectors are picked at any time using expression vector.pickedCount

  • Thx for replies.

    I would like to choose either one does not matter.

    dop2000 i don't understand your sub-event . I specify my vectors are just sprites in the form of rectangular bars that I associate to make polygons

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would just add a variable as a filter

    on collision

    ->variable collisioncount<1, add 1 to collisioncount , do foo

    ... reset collisioncount next tick

  • newt I believe if ball collides with two vectors at the same moment, both vector instances will be picked in one collision event.

    worm1

    Here are a few examples:

    // If you need to process all vector instances which are currently in collision with the ball 
    Ball on Collision with Vector
        For each Vector  ......................
    
    // If you need to process only one vector instance, no matter if the ball has hit 1 or 2 vectors
    Ball on Collision with Vector
        System -> Pick 0-th instance of Vector  ......................
    
    // If you need to know if more than 1 vector is in collision with the ball 
    Ball on Collision with Vector
         System -> Compare two values -> Vector.pickedCount>1
    
    // If you need to pick only one of two vectors using some condition 
    Ball on Collision with Vector
         System -> Compare two values -> Vector.pickedCount>1
               System -> Pick Vector by evaluate <your condition here>[/code:3j641p9u]
  • I dunno, try and see I guess.

    Events run pretty fast.

  • Thx dop2000 for all these solutions, finally I will need to choose a vector in particular because the problem is not the overlap of two vectors but the fact that when the ball touches a side of the vector the collision angle is totally false. I do not know how I'm going to manage this ...

  • worm1

    Is this what's happening?

    You can check if Vector.pickedCount=2 and simply reverse the angle of movement (add 180 degrees).

  • Not exactly dop2000

    It' s when the ball touches the side of the vector as in the example that the angle should be 135 and not 35. I think it may be necessary to do another collision management to use the vectors as they are...

  • Hi ,

    Finally I was able to solve the problem using your method dop2000 thank you

    I detect the number of vectors during the overlapping of the ball and if the number of vectors is> 1 then I add just 180 degrees to the angle of the ball

    Ty again for help!

  • Glad it helped!

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