Bullet/raycast tunneling through a moving part

I am taking a look at an old gun system I made and I plan on remaking it, but while looking at some posts for research purposes, I found one that talks about possible cases where the bullet ignores a moving object.

Blue object is the bullet, red object is a moving part, cases where the object moves first and the bullet checks collision later, which would ignore collision on both.

The problem basically is the chance of a bullet tunneling through a moving object, such as a super fast player going through the pathway of a bullet and the bullet not taking that into account, or the same player moving against the bullet and skipping through the raycast check.

I have no idea how to solve this, as I’ve checked many posts already. Any help or references to another post would be appreciated.

1 Like

The reason why a bullet may ignore moving objects is that: moving object isn’t actually “moving” but rather teleporting to a specific position every frame.

For example, if a player was running at a rate of 2 studs per frame, this would mean that they teleport 2 studs ahead every frame they’re running. If a bullet was to travel in between the player’s old position (the player’s Position in the previous frame) and the player’s new position (the current position of the player/2 studs in front of the old position), then the bullet would have “ignored” the player as from what the bullet knows, it did not collide with anything.

To fix this you can subtract the player’s new position to the player’s old position get a precise hitbox of where the player would have been in between those 2 frames. You could then plug this new hitbox into your collision checker instead of plugging in the object’s position.


Thank you for explaining the situation better than I did. Your solution could help, but there could be a situation where the pathway of the bullet does not go through the middle position between the old and new parts.

I assume that a solution to this would be to execute multiple steps between the two parts, but by then I would have to clone the same part multiple times and CFrame them correspondingly for every frame, which would be quite expensive if I have many moving obstacles/players or a fast projectile with a small hitbox. Do you happen to know any less expensive solution?

1 Like

Instead of having multiple clones, you should have 1 big part that scales and rotates based off the positions like the diagram shown below:

this takes into account every single position that the object would’ve been in-between the 2 frames rather than 1 position (that being the middle)

1 Like

There will be cases where said parts are not solid blocks with a static orientation, such as a mesh or an unanchored part which is constantly changing position and orientation, for such cases I may have to work on it on my own, but for now I believe this is the best solution I may get, so I will take it!

If you end up finding anything that could help with the problem stated above, please let me know. Thank you for you help!

1 Like

For mesh parts you could try Shape Cast, and for constantly moving objects, you could check how far the object has traveled to determine if you should perform this method.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.