# When collisions fail.

Get help using Construct 2

### » Sun Oct 28, 2012 10:07 pm

Sometimes when a bullet clearly is on collision course with an enemy, the collision never registers.

I presume it's because of the bullet - and enemy speed, making the collision never happen since the bullet and enemy simple pass each other during a tick.

Is there a workaround that doesn't involve lowering bullet speed?
B
4
Posts: 9
Reputation: 418

### » Mon Oct 29, 2012 4:35 am

Yes, if you make the bullet move via a loop, you can check the collision inside the loop, which can be a lot faster
Eg:

Repeat 5 times
(action) Bullet move 1 pixel
(sub) On collision
(action) Destroy bullet

Here the bullet moves 5 pixels per tick, and the collision is checked 5 times per tick. Note this will cause a performance hit if you have too many bullets
B
82
S
21
G
15
Posts: 1,038
Reputation: 15,092

### » Mon Oct 29, 2012 8:17 am

Ah, thanks. Makes sense.

I managed to implement it somewhat successful. I still have bullets passing through enemies, apparently not as many, though.
So in order to understand what's going on, I have a question: By what conditions is a collision tested?

If a bullet collides with an enemy within the repeating pattern (say at 5th repetition out of 10), does that count as a collision? Because of this was the case, moving the bullet 1 pixel would always ensure a collision, right?

The reason I'm asking is because that's exactly what I've done, then tweak the bullet speed with the amount of repetitions per tick, but as I wrote before, there's still stray bullets.

Would enlarging enemy hitboxes help?BentOnHell2012-10-29 08:25:48
B
4
Posts: 9
Reputation: 418

### » Mon Oct 29, 2012 11:14 pm

You can use CustomMovement instead of Bullet for fast moving objects. Use the 'On CustomMovement step' trigger to check for collisions every step and adjust the 'pixels per step' setting to increase accuracy. With 'pixels per step' set to 1 you can check for collisions every pixel (though that would be overkill in most cases).

customMovementBullet.capx (r108.2)
B
53
S
28
G
18
Posts: 1,520
Reputation: 24,905