[Rookie Question] What does it take to detect collision?

I guess I’ll start as so many others here on the forum:

“Hi, I’m new to Unity.”

I’ve been following along with some Tutorials and have been reading quite a bit in the Scripting References but now when I’m just “playing around”, trying test things out from scratch I have a problem.

I have two objects:

  1. bullet
  2. target

Both are primitives and have colliders accordingly.

I’ve set the target’s as “trigger”.

I have the following script attached to target:

function Update () {

}

function OnTriggerEnter (other : Collider) {
	Debug.Log("Collision!");
    Destroy(other.gameObject);
}

But the program doesn’t seem to detect any collision.

I’ve been trying to check and uncheck the trigger-property on both, but that doesn’t help.

How am I to solve this?[/list]

Hmm, from all I can see your code and way of doing it in Unity looks right to me. Do you have any red error line in the bottom of the Unity window pointing out that there is some error somewhere? You can open that log also with CMD+SHIFT+C on the Mac.

Edit: Oh, forgot: Do you have primitive colliders attached to both objects or mesh colliders?

Hi, thanks for the reply.

I don’t get any error messages.
They both have prmitive colliders.

Can you post your project and attach it to this thread? Might be easier to debug then. :slight_smile:

http://www.kizozik.com/unity/helloWorld.rar
Thanks

It’s not colliding or fireing trigger events because your shot has no rigidbody component attached. You could safely remove your bulletmovement script and replace it by a “Constant Force” component which makes it easier and has the same behaviour. Then it works. :slight_smile:

file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/Components/class-Rigidbody.html

file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/Components/class-SphereCollider.html

Yeah? Thanks.

I’m trying not to use the physics stuff because I’m afraid it might become too advanced too soon then.

So objects that are to activate triggers MUST BE rigid bodies?

Well, just by adding a rigid body (and unchecking gravity, checking kinematic) it works!

So that’s the trick, eh?

Thank you.

Well, at least one part of the collision must contain a Rigidbody component to trigger collisions. There’s a fine distinction there.

You don’t have to use physics if you don’t want to, although Martin’s solution is a good one.
If you look way down at the bottom of the docs for any of the Collider components, there’s a collision-matrix there (granted, a difficult-to-read one) that should tell you what you’d want to know. In your case, you’d look at the bottom table, and see that you can use a static trigger collider (your target, with a trigger and no rigidbody) and it would get an OnTriggerEnter message when a kinematic rigidbody collider (your bullet, with a non-trigger collider and a rigidbody component with “Is kinematic” checked) passed through it.

Ah, yes, so there is! This will come in handy.
Thank you.