Collision of fast objects does not work. (Yes, I googled it)

In my game a character uses a sword to reflect bullets.

Bullets got struck.

29248-bug.png

Bullets and sword had a collider and a rigidbody attached to them. The collision type was continuous dynamic.

Bullets and sword were controlled only at FixedUpdate function by changing rigidbody.Velocity and, in case of the sword, rigidbody.angularVelocity

DontGoThrough things didn’t help. Changing its layerMask to everything didn’t help. Changing its skinWidth didn’t help

I didn’t want my bullets to be wider or slower.

The collision got correct only after setting Project Settings → Time Manager → Fixed Timestep to 0.001. (0.0015 didn’t help)

The performance became worse when multiple bullets were reflected. After using layer-based collision and reducing max bullets number to 8 it worked with slight lags on PC. On smartphone nothing worked (but it did with lower timestep).


Gravity is (0;0;0)

1)Is there a way to make Physics work?

2)As for advice of making bullets wider: Does relative or absolute width matter? I.e. If I make my camera bigger, redraw all sprites, make speeds of bullets higher will it help?

3)I use 3D physics for 2D game. All rigidbodies have frozen x/y rotation and z position. If I rewrite all the code for 2D Physics will it help?


4)If ideas 2 and 3 are useless, is there an alternative physics engine compatible with Unity which can process collision of fast objects efficiently?

Use the technique Oliver Barraza describes in Mixamo’s First Person Shooter tutorial. You can jump to about the 25:00 mark for the whole thing, or about 27:00 for just the code.

Briefly:

  1. In Start/Awake(), record the starting position in a variable named previousPosition.
  2. In Update(), move the bullet forward using transform.Translate().
  3. In FixedUpdate(), run a Physics.Linecast between previousPosition and the current position to detect if the bullet hit the sword. Then set previousPosition = current position.

Capsule collider + sphere collider works far better than box collder + box collider.

In hemispheres of capsule getting struck is still possible, but they are quite small, and bullets can just be shifted parallel to the sword.