- Home /
Problem with fast bullets (tunnelling effect)
Hi,
I'm facing the tunneling effect problem, which is fast bullets skip certain small objects that appear on their path.
I'm using 2D and my bullets have rigidbody2D and I enabled "Continuous" on Collision Detection via Inspector.
Here is how I fire a single bullet:
Rigidbody2D bulletInstance = Instantiate(BulletPrefab, transform.position, Quaternion.Euler(new Vector3(0,0,0))) as Rigidbody2D;
bulletInstance.velocity = new Vector2(BulletSpeed, 0);
What am I missing? Is my problem is that I change velocity of the Rigidbody2D?
Thanks.
Try decreasing the FixedTimestep: Edit > Project Settings > Time. This does increase the load the physics engine places on the app. You may also want to rewrite the DontGoThroughThings script in the Wiki for 2D.
@robertbu, you should really make that an answer ins$$anonymous$$d of a comment. What you need (and what the DontGoThroughThings script provides) is ray casting. If you don't understand why, or want more information, that can totally be provided.
Thanks. I'm interested to know why "Continuous" doesn't solve this. Are my bullets moving way too fast for even Continuous feature to work and provide proper CCD?
I decreased value of fixed time step to 0.01 and apparently it fixed the problem.
Would someone please tell me pros and cons of using raycasts vs. decreased time step on a 2d game? I.e. which one is more expensive in which ways.
Thanks
Raycast is only valid for tiny objects with basic shape, like a bullet. With a more complex shape, you'd have to place multiple raycasts which in the end would turn out heavy. Continuous detection is then better.
Answer by UnbreakableOne · Oct 02, 2014 at 09:23 AM
What I ended up with and seems to work best is to change DontGoThroughThings for 2D, spend a day pulling my hair out with layer masks, and apparently everything works.
What I love about it is that I can increase speed of my bullets to any aribtrary value and they always hit the target.
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613164030im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with translation and rotation on a rigid body 2D 0 Answers
My bullet wont move forward 1 Answer
Rigidbody2D adding force vs modifying velocity for character jump 1 Answer
2D rigidbody makes my character slowly rise 1 Answer
"Freeze Position" applied to an axis affects the bounciness of the object's collider on that axis. 0 Answers