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:
bullet
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.
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?
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.
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.