Collision for fast moving bullet not detected

0 favourites
From the Asset Store
Particles support animations, collisions, effects and etc.
  • 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.

  • 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.

  • 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.

  • 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.

  • 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: copy.com/euCkQrnoHUPH

  • 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.

  • 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...?

  • 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.

  • 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*dt

  • 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: copy.com/euCkQrnoHUPH

    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.capx

  • I uploaded a cut down version of something I had that does an offset relative to bullet angle/speed rather than absolute co-ordinates.

    It takes the angle [ or angle of velocity] and checks for colliding at offset relative to that, which might help where you've got extremely fast moving stuff and you need to check ahead a bit to see where it might collide, especially if it's small.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ramones' custom bullet example is excellent!

    For me, I like to be able to easily control how far a bullet can travel, including bouncing etc (ie this really depends on your needs as to whether or not my way would work).

    I put this example together this evening - it's not perfect but it shows that when you're shooting super-fast bullets you can get away with an instant enemy kill. I initially went for logging the UID of the target but found that C2 sometimes missed the overlap collision check of my sensor object when I destroyed it at the end of the check loop. For this alternative / quick fix I added a fade-out behaviour to the sensor object to guarantee the overlap was acknowledged. Not perfect, but it does the job...

    Here's the link to the capx:

    dl.dropboxusercontent.com/u/184657779/bullet%20collision%20check.capx

  • Thanks for all the replies. Will test out each method to determine what works best for my project.

    Ramones, the custom movement bullet example you provided seems to work well, but I have one issue. On collision I have functions being called in actions depending on the object the bullets are colliding with.

    Now that I'm using the is overlapping event (instead of on collision), I find that my functions are being called multiple times instead of just once as required, I guess because of the increased accuracy.

    The "stop custom movement stepping" is my first action on overlap (as per your example) before calling my function. Is there any way to execute my functions just once when the is overlapping condition is true - for many ticks?

  • That's why I destroy the bullet when it collides. Do you want it to carry on and hit multiple objects?

  • In some cases, I'd like the bullet to carry on. The workaround I came up with was to have the object being hit spawn a new bullet with the same angle/speed, and this seems to work OK.

    The bigger issue I have with custom movement is that it cuts the frame rate from 60 to 20-30 frames at certain times. My layouts are fairly large (10000 square) and I can have upto 15-20 bullets on screen at once. For accuracy, I need to have at least 10 pixels per step.

    Other than destroying the bullets when they are outside the layout or hit other objects, is there anything else I can do to improve performance? If not I may need to rethink using custom movement.

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