Collision Detection In Unity3D

旧街凉风 提交于 2019-12-02 09:46:05

Alright. I assume that you get neither the OnCollisionEnter nor the OnTriggerEnter call.

Ensure, that the scripts with these methods are on the actual GameObject, that has the collider-component.

OnCollisionEnter-Reference:

"Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached."

To sum up: OnCollisionEnter is only called if you actually use the physics system for moving the objects around due to forces, collisions etc.

If you want to just register a hit without it causing movement via the physics-system, you can use the OnTriggerEnter. In this case, the rigidbody must be on the moving object, and at least one of the involved colliders must be set to isTrigger.

Also ensure that the layers are set to collide in projectSettings->Physics.

Hope this helps you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!