Collision for fast moving bullet not detected

Get help using Construct 2

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

Post » Sun Sep 29, 2013 11:59 pm

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.JohnnySix2013-09-30 00:01:03
Image
B
27
S
9
G
5
Posts: 488
Reputation: 11,948

Post » Mon Sep 30, 2013 3:19 am

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:

https://dl.dropboxusercontent.com/u/184657779/bullet%20collision%20check.capx
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Tue Oct 01, 2013 1:25 am

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?
B
5
S
1
Posts: 44
Reputation: 665

Post » Tue Oct 01, 2013 1:30 pm

That's why I destroy the bullet when it collides. Do you want it to carry on and hit multiple objects?
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Sat Oct 12, 2013 5:58 pm

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.
B
5
S
1
Posts: 44
Reputation: 665

Post » Sat Oct 12, 2013 10:35 pm

In 3D shooters we do not actually use bullets most of the time.

We test to see if the crosshair is over a hitbox , if it is true then we instantly register a hit.

IRL you can not see bullets because they move too fast, so there is no reason to model a 3D bullet , and do a physics simulation to test for a hit.

You can apply the same thing here for Lasers or fast moving bullets... you only need a muzzle flash and maybe a bullet trail. Just test if they are in range, and if they are in line with a bullet. Or if you are using a crosshair do a collision check with the crosshair and the target.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 35 guests