# Physics dont work sometimes (bullets can fly through wall)

**URL:** https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168
**Category:** Physics and Collisions
**Created:** [May 1, 2024, 2:40pm UTC](https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168 "2024-05-01T14:40:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![tudarcat](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/t/54ee81/32.png) [@tudarcat](https://forum.castle-engine.io/u/tudarcat)
#### Post date: [May 1, 2024, 2:40pm UTC](https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168/1 "2024-05-01T14:40:08Z")

</div>

I’m testing physical collisions. However I was surprised to find that the physics collision in the 'examples\physics\physics\_3d\_shooter ’ bullet sometimes fails. Sometimes it goes right through the wall and sometimes it gets stuck in the wall.

How can i fix it?

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [May 1, 2024, 8:29pm UTC](https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168/2 "2024-05-01T20:29:06Z")

</div>

Unfortunately, it is indeed a problem.

We have investigated it with Andrzej Kilijański in the past, trying to “defeat” it, but without a resolution. So far, it does seem it is just a problem of the underlying physics engine (Kraft) and we cannot really avoid/workaround it at CGE level 100% reliably.

In the long run, we plan to add (and maybe make default) other physics engines. Our current best candidate is PhysX, and second best candidate Bullet (see [Roadmap | Manual | Castle Game Engine](https://castle-engine.io/roadmap#_more_physics) ). Comment of course welcome. Both are well-known, popular, feature-rich, open-source, cross-platform → so we’re confident they will serve CGE well. They will likely provide a reliable solution to this.

For now, for Kraft:

1. One practical solution is just to not use such fast flying objects. I know, it sucks. But if possible, this is the simplest working solution – when the objects do not move very fast, the problem disappears, or at least is rare enough to not matter.

2. A solution that _should_ work, but actually doesn’t, is using “continuous” collision detection. This is the mode that _should_ fix such issues. However, we tried with Andrzej enabling it, and no tweaking of options achieved 100% reliable solution to this problem. But you are welcome to try it yourself:

Sorry, no better answer yet. Aside from 1 and 2, the “ultimate” solution will likely come from just using a different physics engine, like PhysX, in CGE.

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [May 6, 2024, 10:54am UTC](https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168/3 "2024-05-06T10:54:38Z")

</div>

1. One other solution, which also a “crazy workaround” (in the sense: it means just resigning from using physics for one use-case):

---

<div class="post-metadata">

### Author: ![tudarcat](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/t/54ee81/32.png) [@tudarcat](https://forum.castle-engine.io/u/tudarcat)
#### Post date: [May 8, 2024, 1:29pm UTC](https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168/4 "2024-05-08T13:29:27Z")

</div>

I tried method 2. but unfortunately it doesn’t work. But when I reduced the bullet velocity the problem did rarely happen. Also, I’ve noticed that the problem seems to be more likely to occur when the FPS is very low. Is this an illusion?

---

<div class="post-metadata">

### Author: ![tudarcat](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/t/54ee81/32.png) [@tudarcat](https://forum.castle-engine.io/u/tudarcat)
#### Post date: [May 8, 2024, 1:32pm UTC](https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168/5 "2024-05-08T13:32:11Z")

</div>

Well, maybe I should try lowering the bullet velocity until there is a better solution to replace it. Thanks for the work. 😀

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [May 9, 2024, 12:09pm UTC](https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168/6 "2024-05-09T12:09:59Z")

</div>

> [@tudarcat](#):
>
> Also, I’ve noticed that the problem seems to be more likely to occur when the FPS is very low. Is this an illusion?

It’s not an illusion, lower FPS can indeed provoke the problem more.

The underlying issue is that when physics uses “discrete” checks, then it only checks each position of the bullet (and not the geometry “stretched” between previous and new position). When the bullet is fast and/or when FPS is low, then there’s more distance between every previous and new position, and so there’s more chance that both previous position will be valid (completely before the wall) and new position will be valid (completely after the wall) and the physics engine will “miss” the fact that in-between there was invalid state (since the bullet traveled through the wall).

The solution AD 2 is in theory the right one – using “continuous” checks means physics engine should check rays between previous and new positions. But it seems it doesn’t work reliably in Kraft for us.

You can read about it more (as the concept applies to all physics engines) e.g. on [https://web.archive.org/web/20240301215026/https://nphysics.org/continuous\_collision\_detection/](https://web.archive.org/web/20240301215026/https://nphysics.org/continuous_collision_detection/) (2026 update: original link does not work anymore, replaced with webarchive) (nice images illustrating where’s the problem).

1. Oh, I also though of another workaround. Increase physics engine frequency. Set `MyViewport.PhysicsProperties.Frequency` to something larger than default (60). For example, try 120 or even more. It may also be necessary to similarly increase `MyViewport.PhysicsProperties.MaxPhysicsTicksPerUpdate`, default 5, to e.g. 10.

---

<div class="post-metadata">

### Author: ![bero](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/bero/32/2973_2.png) [@bero](https://forum.castle-engine.io/u/bero)
#### Post date: [September 20, 2026, 2:55pm UTC](https://forum.castle-engine.io/t/physics-dont-work-sometimes-bullets-can-fly-through-wall/1168/7 "2026-09-20T14:55:08Z")

</div>

It should be fixed in the lastest KRAFT version now, see BeRo1985/kraft on GitHub (commit d8527d428464686bce16e7f446764865ddd82f35).
