How to move target when it collides with a bullet

So, I am trying to make a target for my FPS, but I need to make the physics for the rigidbody for the target itself. And I’ve made a script that should move the rigidbody when the bullet collides with it. But it doesn’t work, so should I even have a rigidbody attached to the target game object at all? What am I doing wrong?

Here’s my script:

function OnCollisionEnter (Other : Collision){


if(Other.gameObject.layer == "Default"){

 GameObject.Destroy(this);

}

if(Other.gameObject.tag == "Target"){
Other.rigidbody.AddForce (Vector3.forward * 10);
}


}

Here’s my rigidbody setup:

16972-rigid_settings.png

You have several issues here. First, if the target is on the ‘Default’ layer, then you will be destroying this script before it executes the it’s add force line. Note that your ‘GameObject.Destory(this)’ is destroying the script, not the game object. You want ‘Destory(gameObject)’ to destroy the whole game object.

In adding force, you likely want to use the direction of the bullet and you will need to add far more force than 10 for an object with a mass of 5. Probably like 2500. So the AddForce() would be something like:

Other.rigidbody.AddForce(rigidbody.velocity.normalized * 2500.0);

In addition, there are often problems with fast moving objects and collisions. There are lots of posts on the issue, so a search will turn up a list of partial solutions. Reducing the fixedTimeStep is the most effective place to start.