Problem with collisions and bullet behavior

Discussion and feedback on Construct 2

Post » Thu Apr 17, 2014 3:09 am

Umm. Its strange.. when my bullet hit the wall something it work.. something not.. depending on where the player shoot the bullet. Here what happen...

Image

The bullet impact animation aren't aligned to the wall. Most the time it is.

My event is basically... once bullet collide create the bullet impact at x and y position of the destroyed bullet. So i expect the collisions to be pixel perfect.. which it doesn't seem to be.

Any ideas how to fix this ?
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Thu Apr 17, 2014 3:27 am

The bullet can not be guaranteed to be pixel perfect. Bullets move X pixels per tick. If that rate is 'fast', the collision will not happen at the wall edge. This has been discussed on other threads.
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358

Post » Thu Apr 17, 2014 3:50 am

That what i would have expected... but there must be a trick to do it. I can't believe there none. :-)
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Thu Apr 17, 2014 9:14 am

You could check for distance and destroy the bullet several pixels before the wall. Another option would be to set it's position on collision to several pixels back. In both cases you got to make case of bullet direction/angle.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Thu Apr 17, 2014 12:02 pm

(Pixel perfect or instant-hit bullets)

+Bullet.count > 0
+For "" from 0 to 5
-Move Bullet 60*dt in angle of Bullet

+On loop ""
+Bullet collides with solid
-Destroy bullet
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Thu Apr 17, 2014 12:26 pm

MadFactory wrote:(Pixel perfect or instant-hit bullets)

+Bullet.count > 0
+For "" from 0 to 5
-Move Bullet 60*dt in angle of Bullet

+On loop ""
+Bullet collides with solid
-Destroy bullet


Can I ask you why are you suing loop, and why 0 to 5?
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Thu Apr 17, 2014 2:40 pm

MadFactory wrote:(Pixel perfect or instant-hit bullets)

+Bullet.count > 0
+For "" from 0 to 5
-Move Bullet 60*dt in angle of Bullet

+On loop ""
+Bullet collides with solid
-Destroy bullet


Interesting. I was about to end up with a pretty complex algorithm but i decided to take a look at your snippet of code. However, like megatronx, i don't fully understand the logic behind this snippet of code.

From my understanding... you seem to use the loop for detecting if the bullet collide with the wall. Why? Plus, isn't Bullet collide a triggered event ?

Code: Select all
-Move Bullet 60*dt in angle of Bullet


So your not using the behavior, your doing it manually. Is there a reason for this ?

Other than that... i found a way of doing it. Put a detector in front of your bullet (pixels ahead) when it hit the wall it stand still until the bullet reach the wall, during that time you can adjust the position of the detector and when the bullet hit finally the wall, destroy the detector and create the bullet impact at his location. The detector must match the same bullet trajectory for this to work. So for direct trajectory this would be easy..
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Thu Apr 17, 2014 3:16 pm

I learned it in a MMF tutorial years ago. There are probably more sensible ways of doing it but whatever, it works. The idea is that even though the bullet is moving, say, 5px per tick, collisions are being checked for each pixel it moves.
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Thu Apr 17, 2014 6:09 pm

MadFactory wrote:I learned it in a MMF tutorial years ago. There are probably more sensible ways of doing it but whatever, it works. The idea is that even though the bullet is moving, say, 5px per tick, collisions are being checked for each pixel it moves.


OK! I get it now. Interesting.However, i sense a performance problem. You basically check even if there is not collision around. But maybe the cost is not high enough to have any impact. But if you shoot your projectile far up to 400 pixels.. you will have more than 400 loops. So firing many projectile at the same time might be costly. But thanks! :-)
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Fri Apr 18, 2014 12:14 pm

OK, here's mine.

Code: Select all
Bullet is on screen
For each bullet
distance(bullet.X,bullet.Y,tile.X,tIle.Y) < 10 - destroy bullet.


Of course you can replace 10 with any other number that works best for your set up.

Now I'm not sure if Bullet is on screen & For each bullet are necessary. You will have to test how it works without one or both of them. I'm using For Each often, because otherwise event applies to all instances of same type ( I'm bit confused about this since @Ashley wrote somewhere that it is working like a loop even without a loop, but from my tests it doesn't work that way, and I tend to use for each )

Another option to do is to make condition "Bullet overlapping at offset". if you set X to "-10 & 10" , and Y to "-10 & 10" too, should work ( if not try "-10 | 10"). Let me look at one of my prototypes to remind myself.

[email protected] Right, forgot that that project files got corrupted due to crash. Oh well.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests