- Home /
Detecting collision between two objects without triggers.
I want my projectile to knocked down the objects it hits (rigid body vs rigid body) and disappear right after doing that. The only way I can detect a collision via script is by assigning a trigger. The problem is that once I assign a trigger to the projectile it just disappears when touching the object it supposed to knock down without affecting it.
Sorry for necro but there was no answer and I'm wanting the same thing :|
These 4 answers are basically the same, and they are all valid... Again, check for unity's documentation about OnCollisionEnter on the first answer...
Answer by Moohasha · Mar 02, 2012 at 07:24 PM
Why do you have to use a trigger? Both objects should have colliders that AREN'T triggers, then just use the OnCollisionEnter function on your bullet.
Answer by Exalia · Sep 03, 2013 at 12:26 PM
I managed to get this working immediately after posting so I'll paste it here
using UnityEngine;
using System.Collections;
public class ColliderScript : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Enemy")
{
Destroy(other.gameObject);
}
}
}
Yes, it is the same as the last 4 answers with better, format, I guess you are looking to get some rep, so here, take 10 points
I'm here to learn oddly enough...
Earlier I created a script that used on TriggerEnter as quite a few tutorials use that to create similar effects like pick up but I needed both objects to be rigid.
I googled it, found this page did a copy and paste and it didn't work, I changed it slightly (tags not names) and it worked.
I didn't come here looking for "points" this isn't a dick waving contest its people trying to help eachother
why would some one who wants to learn be copy pasting code?, if an answer said OnCollisionEnter, and it has the link to unity's documentation, that's more than enough to learn how to use it, also, use names for especific objects, and tags for groups of objects, you just have to make sure which you will be using and check the object has the one you need, good luck, and sorry if I offended you somehow
That's like saying why do people who make better cars use wheels. I'm not here to invent the next best thing, a very basic function wasn't working. Not because I didn't know what I wanted to do or how to do it but because I didn't know which word to type.
There seems to be this odd vibe from some people on here where they want you to give them a reason to help you
"Why do you need this?" "You don't need to do that do this it's better"
It's unity answers not unity opinions
I don't need to learn how OnCollision works it's self explanatory and is present in every game engine I've used. what I did need to learn is that it exists and how to spell it. That's it.
Thanks for initially assu$$anonymous$$g the worst and continuing to insult my intelligence.
Answer by poncho · Mar 02, 2012 at 08:32 PM
you should use the collision methods
void OnCollisionEnter(Collision myCollisionInfo)
{
}
you just need to make sure you have Collider attached to the gameobjects you are going to collide
Answer by Michael 8 · Mar 02, 2012 at 08:46 PM
Thanks for the help!
I'm using:
void OnCollisonEnter(Collision collision)
{
Destroy(gameObject);
}
And nothing happens, so obviously I'm doing something derpy... :-/
Your answer
Follow this Question
Related Questions
On Trigger Enter, Collide with object, specific collision 1 Answer
Animation with frozen player ?? 0 Answers
Why the npc character walking strange when using a Rigidbody and Is Kinematic on enabled ? 1 Answer
How to enter trigger a certain amount of times before executing code? 1 Answer
Open door = load scene c# issues 4 Answers