- Home /
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?
$$anonymous$$y 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. ==
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.
@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.
@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.
Answer by skovacs1 · Oct 27, 2010 at 06:35 PM
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.
Just before you answered, saw the note in script reference. So my question would now be... How to achieve similar results without a RigidBody?
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.
you can always have a rigidbody without gravity have you tested that out if that's what you are looking for.
Answer by Jonas Planck · Oct 27, 2012 at 08:44 AM
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.
You only have to set is$$anonymous$$inematic = true for the object not to be at the mercy of physics. See this unityGE$$anonymous$$S article for a discussion of how to make collisions and triggers work.
@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.
Thanks JONAS, I had an invisible plane that I wanted to create an OnCollisionEvent. But I didn't want it to interact with the object passing through it. Your solution solved my problem, although I'm not sure if there is a processing penalty.