x


Collision Detection without a RigidBody

Hellow,

I'm using a OnTriggerEnter, but for some reasons.. It doesn't seem to detect the collision.

Used the method on other scripts, all work, but not for this particular one.

Here is the snippet of code

function OnTriggerEnter (other : Collider) {

     if (other.gameObject.GetComponent(Tagger).Meteor == true) {
        other.gameObject.GetComponent(MeteorMove).explode = true;
    }
}

EDIT

Saw it was because I missed that I needed the RigidBody. Is there a way to get a similar result as a OnTriggerEnter without a RigidBody?

more ▼

asked Oct 27 '10 at 06:11 PM

Oninji gravatar image

Oninji
332 43 47 50

My suggestion to you is throw a print statement just before that if statement and see if the function is even firing. If so, your problem could be that the collider's game object doesn't have the component you're looking for or perhaps the code you're triggering (the boolean explode) doesn't give you the visual feedback you're expecting so you believe it isn't doing anything. Just a thought. Cheers. ==

Oct 27 '10 at 06:20 PM equalsequals

Do you realize that "Hellow" is not a word? The word you seem to be looking for would be "Hello". After reading this in several of your questions, I thought it best to let you know. It's not likely a typo because 'w' is so far from the 'o' or ',' that you are typing around it. It's even more odd as a few of your questions don't have this mistake.

Oct 27 '10 at 06:44 PM skovacs1

@Skovacs, that's plain unconstructive.... @equalsequals I was checking through the inspector and did used print. But well, as I stated in the edit I had forgot that I needed the Rigidbody to fire the function. So now I'm checking around to found another mean of trigerring my function is a similar maneer without using a rigidbody. But thanks.

Oct 27 '10 at 06:51 PM Oninji

@Oninji - How is that not constructive? I am helping you 'construct' better English sentences and questions. I don't mean it in a malicious or critical way. I was simply trying to help you improve your English language skills. I wouldn't have mentioned it if you hadn't made the same mistake in 11 of your 14 questions.

Oct 27 '10 at 07:00 PM skovacs1
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I assume you are asking, "Why is this collision not being detected?" rather than something else about the undetected collision.

As per equalsequals' comment, it is possible that the collision is happening, but that your if statement or however you are identifying that the collision is happening is failing rather than the collision not being detected. Using Debug.Log and/or print statements would help you identify which is the case.

The docs on OnTriggerEnter clearly state:

Note that trigger events are only sent if one of the colliders also has a rigid body attached.

Do you have a Rigidbody or CharacterController on one of the colliders?

How fast is your object moving? It is possible that one collider is passing over the other without generating a collision. If this is the case, it would be better to adjust your scene, but if that is not feasible, then if you have a Rigidbody, you might consider changing your Rigidbody's collision detection to Continuous.

more ▼

answered Oct 27 '10 at 06:35 PM

skovacs1 gravatar image

skovacs1
10k 11 25 92

Just before you answered, saw the note in script reference. So my question would now be... How to achieve similar results without a RigidBody?

Oct 27 '10 at 06:42 PM Oninji

If you do not have a Rigidbody or CharacterCollider, OnTriggerEnter() will not be called. If you cannot have one of those, then you will have to check for the collisions with either raycasts, spherecasts or capsulecasts in an update function of some variety.

Oct 27 '10 at 07:03 PM skovacs1

you can always have a rigidbody without gravity have you tested that out if that's what you are looking for.

Sep 18 '12 at 03:22 PM tonydemot
(comments are locked)
10|3000 characters needed characters left

I just spent a few hours banging my head against this problem... I found a solution by adding a rigidbody component, and opening the constraint dropdown of that component and checking all the boxes. This way, the object still collides with the trigger, but it's not at the mercy of physics, and it still obeys it's transform instructions.

more ▼

answered Oct 27 '12 at 08:44 AM

Jonas Planck gravatar image

Jonas Planck
31

You only have to set isKinematic = true for the object not to be at the mercy of physics. See this unityGEMS article for a discussion of how to make collisions and triggers work.

Oct 27 '12 at 08:45 AM whydoidoit

@whydoidoit: Thanks! This resource will come in very handy... I'm also new to scripting, so this will help me in ways I haven't even foreseen yet.

Oct 27 '12 at 09:35 AM Jonas Planck
(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:

x5270
x2584
x2171
x1765
x356

asked: Oct 27 '10 at 06:11 PM

Seen: 8132 times

Last Updated: Oct 27 '12 at 09:35 AM