Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

The "shot" is supposed to collide with the left bumper and then be destroyed, but the shot goes right through it. Both objects have a box collider.

The following is the code I am using:

#pragma strict
var speed : int = 2;
var collided_with : GameObject;

function Start () {

}

function Update () {
    transform.Translate(Vector3(-1 * speed * Time.deltaTime, 0, 0));
}

function OnCollisionEnter (col : Collision) {
    if(collided_with.tag == "Left"){
        Destroy(gameObject);
    }
}

I have made sure that all the tags are assigned correctly and that there are no spelling errors. The variable collided_with is also assigned to the left bumper. What am I doing wrong?

share|improve this question
    
I would be aware of how fast is your item going as this can affect if it collides at high speeds. If the speed is too high then the next position update before it hits a "wall" is going to place the item behind the wall without a collision activating. –  Blue May 19 at 13:01

2 Answers 2

up vote 3 down vote accepted

Collider is only one piece of the puzzle -- it detects a collision -- but each object in the collision should also have a Rigidbody attached if you want an actual collision response.

Also, depending on the speed, you may need CCD - Continuous Collision Detection.

share|improve this answer

You should consider using a RigidBody on some of your objects. There are 3 types of collision detection for a RigidBody component. Discrete is fastest, but it can result in the "bullet through paper" problem that you are having.

https://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-collisionDetectionMode.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.