Avoiding collision events from running twice.

Get help using Construct 2

Post » Sat Jul 21, 2012 4:37 pm



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.
B
18
S
4
G
4
Posts: 68
Reputation: 3,127

Post » Sat Jul 21, 2012 4:46 pm

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?
B
22
S
7
G
3
Posts: 189
Reputation: 4,270

Post » Sat Jul 21, 2012 4:57 pm

You can use the "Trigger once " Event !
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

Post » Sat Jul 21, 2012 7:49 pm

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.BlueSkies2012-07-21 20:00:17
B
18
S
4
G
4
Posts: 68
Reputation: 3,127

Post » Sat Jul 21, 2012 8:39 pm

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.
B
19
S
5
G
1
Posts: 104
Reputation: 2,920

Post » Sun Jul 22, 2012 8:07 pm

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.
B
18
S
4
G
4
Posts: 68
Reputation: 3,127

Post » Sun Jul 22, 2012 8:34 pm

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.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests