- Home /
Innacurate terrain collision with fast rigidbody
Hello! Before I detail my question, please know that I am mostly aware of the collision-caveats associated with very fast rigidbody collisions and that it's generally not a good idea, but I need projectiles that behave in a realistic manner (ie, air drag and bullet-drop etc etc) - insta-hit raycast bullets are not an option. Unfortunately I don't have time (nor the mathematical alacrity!) to completely write my own projectile physics system
I am simulating projectiles solely with the physics engine and have projectiles at speeds between 50,000 - 100,000. Now everything works perfectly (really) with collisions on meshes with a variety of colliders.
The only innaccurate collisions I can detect are on the Unity terrain colliders.
While no bullet misses per se, the bullet impact points are always slightly further ahead then they should be. The effect is increased the faster the projectile is set. At 50,000 (the speed of my tank shell) it's not too bad, but at 100,000 (the speed of my bullets) the impact points are usually about 10 feet ahead of where they should be.
Using trail renderers to try and debug the problem it shows that the bullet is actually hitting where it should be, but then kind of entering the terrain and bouncing out further ahead, and that point further ahead is where the collision physically registers. SO my impact effects always look way off.
The image below illustrates the problem. The line indicates where the bullet should be and IS initially hitting, but then as you can see the dust effect is placed a fair bit up the track...
All bullets are set to continuous dynamic with a capsule collider slightly bigger and longer than the mesh itself. Fixed timestep is set to 0.01.
Is there a way to detect more accurate terrain collider collisions? Or is there an entirely better way to go about it?
Any suggestions or insight would be very welcome :)
Answer by Benproductions1 · Oct 16, 2013 at 10:53 PM
Hello,
The reason for your "inaccurate" terrain collision is due to the many optimisations what are done with the terrain collision system.
When it comes to projectile physics, it's either you wirte your own (which you don't want to do), or you deal with the many inaccuracies of rigidbody physics. There is no midpoint unless you want a really high framerate impact from just physics.
Hope this helps, Benproductions1