Collision of object with player

2019-03-07 05:03发布

So I have a bit of an issue with some unity script (Another one, I've given up any interest of using unity outside of my required class projects). So I have a moving object, a ceiling to be specific, and I have it lower and 'crush' the player. However, it's not working. The ceiling moves, but nothing happens when it collides with the player. It used to work if the player was moving when it hit them but it isn't any more and I haven't changed any of the script so I don't know why that's happening. My teacher had a suggestion on how to fix this but he wasn't specific enough on how to actually do it.

His solution was to place a box on the player controller and make that have a reaction when it hits the ceiling. My question is how do I do that, or is that a better way? (Keep in mind I am very bad at deciphering syntax without some sort of example)

1条回答
成全新的幸福
2楼-- · 2019-03-07 05:48

Interesting suggestion from your teacher. I would put a character controller on your player, which you seem to have already. Then I would add the collision code:

void OnCollisionEnter(Collision c)
{
   // die.
}

Then add a box Collider and Rigibody to the roof. I would also add this code above to the roof.

查看更多
登录 后发表回答