物体与玩家碰撞 [英] Collision of object with player

查看:72
本文介绍了物体与玩家碰撞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我对某些统一脚本有一些问题(另一种,我放弃了在所需的班级项目之外使用统一的任何兴趣).因此,我有一个移动的物体,一个特定的天花板,然后将其放低并压碎"玩家.但是,它不起作用.天花板移动,但是当它与玩家碰撞时什么也没有发生.如果玩家在击打它们时正在移动,它就可以正常工作,但是现在已经没有了,而且我没有更改任何脚本,所以我不知道为什么会发生这种情况.我的老师对如何解决此问题提出了建议,但是他对如何实际解决此问题还不够具体.

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)

推荐答案

老师的有趣建议.我会在您的播放器上放一个角色控制器,您似乎已经拥有了.然后我要添加碰撞代码:

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.
}

然后在屋顶添加一个对撞机盒和Rigibody.我还要将此代码添加到屋顶上.

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

这篇关于物体与玩家碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆