[Solved] Use OnCollisionEnter or OnTriggerEnter without Rigidbody ?

It possible to use OnCollisionEnter or OnTriggerEnter in object without rigidbody ?

I found these answers:
https://answers.unity.com/questions/33120/oncollisionenter-doesnt-work-without-rigidbody.html

https://answers.unity.com/questions/536674/how-to-detech-collision-without-rigidbody.html

When using these I think both need at least one of the gameobjects to have a rigidbody for collision processing. It doesn't have to be an non-kinematic rigidbody though - so if you have objects you don't wanna do physics (like gravity) for, you can attach a rigidbody still to it, and set the kinematic checkbox. Then when that object hits your trigger or another object with OnCollisionEnter then it should work.

10 Likes

Thank you MD.

No problem, good luck! :)

guys i have tried it with both my objects with rigid body and one is a bullet but it doesnt work it just pushes my character away and doesnt do anything that i have programed plz help

Can't really help you out without knowing what your code looks like :P

[quote=“haitham-hub”, post:5, topic: 707608]
guys i have tried it with both my objects with rigid body and one is a bullet but it doesnt work it just pushes my character away and doesnt do anything that i have programed plz help
[/quote]

Did you check the box to Is Trigger ?

Also, it is enough to have a parent with rigidbody. So if you have multiple objects and dont want too many rigidbody than just make a parent and attach rigidbody.

These functions arent called if both of your interacting objects do not have a rigidbody. Atleast one of those have to have a rigidbody in order for OntriggerEnter or OnCollisionEnter to be called.
Now you have two options. You can add a rigidbody to any one of your objects and keep it kinematic to avoid any hinderances with your scripted procedures. But because that is too costly if you have many objects so instead of going for a whole grid you can use this function

bool PointInBoxCollider(Vector3 point, BoxCollider2D box)
{
Vector2 center = box.bounds.center;
Vector2 extents = box.bounds.extents;

Vector2 rightTop = center + extents;
Vector2 leftTop = center + new Vector2(-extents.x, extents.y);
Vector2 rightBottom = center + new Vector2(extents.x, -extents.y);
Vector2 leftBottom = center - extents;
if (point.x < rightTop.x && point.x > leftTop.x && point.y < rightTop.y && point.y > rightBottom.y)
return true;
return false;
}

What it does is that it takes a point and checks if that point lies in a given box collider. You can call this function in one of your objects and check in Update if your other object lies within the box collider by passing its transform.position in the function