Avoiding collision events from running twice.

  • <img src="http://img.photobucket.com/albums/v43/hyudol/screenshot101.png" border="0" />

    In my game, the ball bounces against the player-created yellow barriers that you see. For this I've used the Reverse Custom Movement event. The problem arises when the player creates two yellow lines in the same place, one on top of the other, at which point I presume the ball bounces against both lines simultaneously, and runs the Reverse Custom Movement event twice, therefore the ball doesn't change direction.

    A related problem is with collision against the blue outer walls, which are made up of 32x32 tiles. Note the number on the ball. This decreases every time the ball bounces against a wall/yellow barrier, but sometimes, when bouncing against the outer walls the counter decreases by 2. I presume this is because the ball is bouncing at the point where two tiles meet, therefore bouncing against both and running the tile's collision event twice?

    Any workarounds for this double collision would be appreciated. Thank you.

  • You could use a variable to decide if the counter must decrease. And then set this variable on collision, but a apply a wait before the countdown applies.

    Eg. ball hits yellow, set variable - wait 0.1 second, then decrease the timer.

    I don't know if I explained very well?

  • You can use the "Trigger once " Event !

  • Superkew - That is the workaround I've currently adopted, I just thought there might be a more robust solution.

    Kbdmaster - I've looked for such an event but can't find it. The manual says it's under 'Special conditions' but I only see two events there: 'Is in preview' and 'Is on mobile device'?

    EDIT - Okay, I found it. It only shows up if the System event is a seperate event and not another condition to my collision event. I tried making is a sub event to the collision event, with the Reverse Custom Movement as its action, but nothing changed.

  • Think about it like this: You need the yellow line to only collide with the ball the first time. The simplest way to track this would be with a boolean variable on the yellow line, and also check for when the yellow line DOESN'T collide with the ball. It could look something like this:

    For Each: Yellow Line --> If Yellow Line collides with Ball & Yellow.Boolean = false --> Reverse & Yellow.Boolean = true

    Else --> Yellow.Boolean = false

    As long as you check for a boolean during the first collision and change the boolean on the first collision and when it is not colliding, it should work fine.

  • bWard, I haven't had an opportunity to try that yet, but it sounds like that tests for one line being collided with twice, whereas that's not the problem; the problem is that the ball collides once with 2 seperate lines, because they occupy the same space.

  • Try Construct 3


    Try Now Construct 3 users don't see these ads
  • Yeah, none of these solutions will work since it will collide with two different instances anyway and therefore register two collisions.

    You can either prevent lines from being created too close to each other, or you can create a delay like discussed above. That's the best I can come up with though.

Jump to:
Active Users