- Home /
Colliders don't work when object has large speed!
Colliders don't collide when object has large speed and object goes through walls!!! But with low speed colidrs work perfectly.
Answer by syclamoth · Mar 21, 2012 at 12:06 PM
Are we talking about bullets here? Small objects travelling at high speed? Look up raycast colliders and linecasting. Simply, you need to improve on the basic collision detection provided by physics by using Physics.LineCast(previousPoint, currentPoint)- this will detect if the bullet should have hit a wall.
If that's not enough detail for you, feel free to use the search bar like you should have done before posting this.
How to use physics.linecast? Yes, i saw Unity script reference
See! Look at all the other answers. Come on, there are step-by-step instructions actually in the manual you claim to have read. And in any case, you didn't specify what the object was but explain to me- in what way is a bullet not kind of "metal ball"?
Answer by Rabbit-Stew-dio · Mar 21, 2012 at 01:04 PM
The physics engine uses discrete steps to test for collisions by default. The "fixedUpdate" runs several times per frame. On each fixed-update your model is tested for collisions. When you use "discrete" collision tests, your objects jumps between frames.
When your object is small and fast moving, these jumps can make you miss collisions inbetween.
Example: Assume you have a bullet flying at 1000m/s. The setting for Fixed Timestep (via "Edit->Project Settings->Time") is left at 0.02s. That means your bullet jumps through the scene in 20m steps (1000m/s * 0.02s = 20m).
To make sure your bullet hits everything, you have three options:
(1) You can make the Fixed Step setting smaller. To test for each meter, you would have to set it to 0.001 instead. Drawback: This makes your physics calculation 20 times more expensive (0.02 / 0.001 = 20), as you now invoke "fixedUpdate" 20 times more often for each frame.
(2) You can set your collide-setting on the bullet's rigidbody to "continuous" or "continuous-discrete".
(3) You can do it manually by adding a script to your bullet that linecasts backward as described by syclamoth.
I would use the raycast as I would think is less computation hungry and result is the same. Should you want to see the actual bullet flying, you could still instantiate the bullet for visual effect(maybe even with a tiny particle trail) and raycast for collision. Any suggestions?
Answer by fafase · Mar 21, 2012 at 12:24 PM
This is a common frame displacement problem in computer game.
Your object is moving at high speed let's say 500m/s, if you run at 100fps that 5m/fps so every frame your bullet is skipping 5m. If you stand at 0 then it will hit at 5 ,10, 15... but in between, safety.
That is why as mentioned by @syclamoth you need to use raycast. Or both but at least raycast.
Your answer
Follow this Question
Related Questions
bullets flying through enemy 1 Answer
physics.OverlapSphere colliders 1 Answer
Speed/trigger only working once 0 Answers
Rotation Ease-In-Out with MAX Rotation Speed 1 Answer
Pathfinding with specific end-direction and turning speed limit 0 Answers