Collision for fast moving bullet not detected

Get help using Construct 2

Post » Wed Sep 11, 2013 11:41 pm

I have a projectile (with bullet behavior) which is 13 x 5 pixels and has a speed of 6000. When it hits a sprite with a width of 15 pixels an animation is triggered using the on collision event.

I'm finding that a lot of the time, the bullet passes straight through the sprite without triggering the animation. If I reduce the speed of the bullet significantly (say to 100) then the collision works fine.

Is this a limitation of having 60 ticks per second? Is there any way around this? I have tried the other collision events, but short of making my collision polygon larger (which I don't want to do) I can't find any way around this.
B
5
S
1
Posts: 44
Reputation: 665

Post » Wed Sep 11, 2013 11:55 pm

I had this problem too. What I did was make the bullets around 150 pix long (not the image, but the canvas). So far it seems to have worked even though the image is larger.
B
40
S
12
G
1
Posts: 533
Reputation: 4,149

Post » Thu Sep 12, 2013 12:07 am

6000*1/60 = 100 pixels per tick at 60 fps so it would easily pass through something that's 15px wide.

You could use custom movement for more accurate collisions. You can set the 'stepping mode' and set 'pixels per step' to 5 so you can check for collisions every 5 pixels.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Thu Sep 12, 2013 12:39 am

Making the canvas (and collision polygon) length 100+ pixels works but sacrifices a little accuracy in the collision.

The custom movement option sounds like the ideal solution, will do some research into this.

Thanks both for the quick response.
B
5
S
1
Posts: 44
Reputation: 665

Post » Sun Sep 29, 2013 10:43 am

I have tried the custom movement behavior on my projectiles to improve collision accuracy, but I'm facing 2 issues.

1. The projectile is not firing from player angle
2. Even with stepping mode set to 1 pixel per step my collisions are not detected

Capx link: https://copy.com/euCkQrnoHUPH
B
5
S
1
Posts: 44
Reputation: 665

Post » Sun Sep 29, 2013 2:13 pm

Did you try to use the physics behavior on top of the bullet behavior?

There is an option called "Enable enhanced collision detection for fast moving objects" in the physics behavior of an object.

I was able to fix a missing collision issue with that too, but I don't know if your bullets might be still to fast or if your project allows you to use physic behavior.

B
34
S
9
G
3
Posts: 206
Reputation: 7,851

Post » Sun Sep 29, 2013 3:25 pm

Use an invisible stepping sensor to determine if the bullet will kill anything before it is fired (like the laser examples). If a future collision is detected, get the UID of the enemy that is about to die (or set an 'about to die' variable). Then fire the bullet with a range to expire equal to the length of the collision sensor. On bullet expire, kill the enemy. Should work well enough to fool even an expert observer.

Written on mobile so very brief, but I hope this makes sense...?
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Sun Sep 29, 2013 5:28 pm

MACPK: I'm avoiding Physics in my project, but as a test I enabled physics collisions on the objects and set the physics bullet property to yes on the projectile, and it didn't seem to make any difference. Is there any other non-framerate dependent/non-physics method of detecting collisions for small fast moving objects (with a speed of 10000+)?

Colludium: I think I understand the method you're describing. An example would be helpful.
B
5
S
1
Posts: 44
Reputation: 665

Post » Sun Sep 29, 2013 5:44 pm

For extremely fast bullets, instant-hit bullets, or pixel-perfect bullets, you need to use loops. Something like...

+Bullet.Count > 0
+For 1 to 5
-Set Bullet.X to Self.X+60*dtMadFactory2013-09-29 17:46:10
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Sun Sep 29, 2013 7:35 pm

[QUOTE=terence] I have tried the custom movement behavior on my projectiles to improve collision accuracy, but I'm facing 2 issues.

1. The projectile is not firing from player angle
2. Even with stepping mode set to 1 pixel per step my collisions are not detected

Capx link: https://copy.com/euCkQrnoHUPH[/QUOTE]

Two problems there. You need to set the angle after setting the speed. And you need to use the 'on step' trigger along with 'is overlapping' to check for collisions every step.

Here's an old example I made of a custom-movement bullet:
customMovementBullet.capx

And a ball bouncing between two 1px wide walls:
custom movement stepping.capxramones2013-09-29 19:37:45
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Next

Return to How do I....?

Who is online

Users browsing this forum: Armench, dop2000, Jackriduk, kiki4construct and 23 guests