- Home /
FPS Tutorial: Why do my grenades go through the walls?
I have set up the missile launcher and added the script to instantiate a grenade and change its velocity but the grenades just go right through the walls, about 90% of the time sometimes they hit the wall but then they just fall through the floor lol.
Answer by e-bonneville · Mar 20, 2010 at 10:17 PM
There is a common problem that is the cause of this. It is called "collision tunneling". It happens when the projectile is moving so fast that one frame it is directly in front of the wall, and the next, it has passed right through it.
This script may be of use to you:
function FireOneShot () { var direction = transform.TransformDirection(Vector3.forward); var hit : RaycastHit;
// Did we hit anything? if (Physics.Raycast (transform.position, direction, hit, range)) { // Put your firing script here }
That uses a raycast to tell if the grenade hits anything an instant before it does. Give it a try... Good luck!
Ah ok thanks, I assumed that PhysX would handle quantum tunneling.
Answer by patricklorio · Mar 20, 2010 at 10:09 PM
In the game's settings there is a tab called time. In that you can play around with the sub settings. the lower the number, the better the physics. I don't have unity on this computer so I cannot see exactly which one determines the physics or time but I think it is the second text field. Remember don't go crazy with the number cause it eats up the memory.
Answer by Eugene · Mar 24, 2010 at 10:02 PM
Taken from the Unity3D car tutorial (http://www.gotow.net/andrew/blog/?page_id=78):
NOTE: I generally create colliders as separate child objects of the main body, this way I can have multiple colliders in the general shape of the car. You could use a mesh collider for this, but mesh colliders do not work well for objects moving at high speeds.
Perhaps this explains why my grenades go through the walls because I am using a mesh collider for the level object. It seems like a real pain to set up individual box colliders for the entire level mesh in Unity, is there a way to do this in Blender or an external 3D app? If not perhaps this would be a good addition to the program...