x


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.

more ▼

asked Mar 20 '10 at 08:25 PM

Eugene gravatar image

Eugene
31 2 2 3

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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!

more ▼

answered Mar 20 '10 at 10:17 PM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

Ah ok thanks, I assumed that PhysX would handle quantum tunneling.

Mar 20 '10 at 11:29 PM Eugene
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 20 '10 at 10:09 PM

patricklorio gravatar image

patricklorio
1

(comments are locked)
10|3000 characters needed characters left

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...

more ▼

answered Mar 24 '10 at 10:02 PM

Eugene gravatar image

Eugene
31 2 2 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2584
x1947
x84

asked: Mar 20 '10 at 08:25 PM

Seen: 1741 times

Last Updated: Mar 20 '10 at 08:25 PM