3
\$\begingroup\$

i know if your object has a Collider you can sense another Collider with OnCollisionEnter function or... and you can sense another collider with trigger with OncollsionEnter function and... but i want to sense other object with trigger even with collider or even with trigger. i cant sense otherobjects that have triggers. for example i have bullet that as i dont want to collider have any physics i turned it to trigger but how can make a charcter to sense it?

Thank you for helping

\$\endgroup\$
1
\$\begingroup\$

It's more than simple, but remember you must have attached rigidbody on either object.

Second is tag. It is one of the many ways to detect any specific object through tag. Create a specific tag by selecting any GameObject from hierarchy, in inspector click on tag drop down and add a new tag, for example bullet. Set the tag of your bullet to the newly created one, i.e. bullet

Now I'm assuming that your character have rigidbody attached then you can detect through script attached to your character by,

void OnTriggerEnter(Collider collider)
{
    if(collider.gameObject.tag == "bullet") // this string is your newly created tag
    {
        // TODO: anything you want
        // Even you can get Bullet object
        GameObject strikingBullet = collider.gameObject;
    }
}
|improve this answer|||||
\$\endgroup\$
5
\$\begingroup\$

You should read this documentation

There is this image here you can use as a reference:

Collision Matrix

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I have a target that is Kinematic Rigidbody with a trigger collider, and a bullet which is a non-kinematic Rigidbody with a regular collider, and it doesn't work. However, I have the targets moving up and down, and they do report collisions with the ground. \$\endgroup\$ – Aaron Franke Jul 18 '19 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.