Child of Player not detecting collision with rigidbody on other object

╄→尐↘猪︶ㄣ 提交于 2021-02-11 15:21:40

问题


I have a player with a character controller, and a child object with a capsule collider extending a little bit out of the player's characterController to detect if the player jumps on a cube with a rigidbody on it. The child of the player has a tag called "hammer", and the rigidbody cube has a script on it.

For some reason, the child is not detecting collisions with the rigidbody. It only does so when the player and the child is touching the rigidbody. Here is the code for the rigidbody cube:

private void OnCollisionEnter(Collision other) {
   if(other.collider.tag == "hammer") {
       Destroy(gameObject);
   }
}

NOTE: Can't add rigidbody to player otherwise spazzles out like spazzling is going out of style.


回答1:


Just needed to add rigidbody on the child and the tag, and didn't need the rigidbody on the external object.



来源:https://stackoverflow.com/questions/54876848/child-of-player-not-detecting-collision-with-rigidbody-on-other-object

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