玩家从地板上掉下来 [英] Player is falling through the floor

查看:31
本文介绍了玩家从地板上掉下来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我什么都试过了.无论我在它下面放置什么样的游戏对象(立方体等),玩家都会失败.它有一个圆形煤矿和一个刚体.

I've tried everything. The player falls through regardless of what kind of GameObject (cube etc) I place under it. It has a circle collier and a rigidBody.

如何阻止物体从地板上掉下来

How can I stop the object from falling through the floor

我应该提一下,玩家一旦接触到任何东西就应该死,所以我不知道如何解决这个问题.

I should mention that, the player is supposed to die once it comes in contact with anything, so I don't know how to approach this.

推荐答案

如果 Object 从地板上掉下来,请检查以下内容.

If Object is falling through the floor, here are the things to check.

1.Collider 是否附加到该对象上?如果没有,则将 Collider 或 Collider2D 附加到该对象.

1. Is Collider attached to that Object? If not then attach Collider or Collider2D to that Object.

2.是否在任何对象碰撞器上启用了 isTrigger?如果是,则在两个碰撞器上禁用 IsTrigger.

2. Is isTrigger enabled on any of that Object Collider? If yes, then disable IsTrigger on both colliders.

3.如果 Rigidbody 附加到 GameObject,请确保玩家在点击Play"之前 100% 高于地板,否则您会遇到更多问题.

3. If Rigidbody is attached to the GameObject then make sure that the player is 100% above the floor before clicking "Play" or you will experience even more problems.

4.游戏对象的大小可能很小.真的很小.对象在与另一个对象碰撞之前可以达到的大小是有限制的.尝试调整对象的大小,然后将相机向后移动.

4. The size of the GameObject might be small. Really small. There is a limit on what size the Object can be before it can collide with another Object. Try resizing the Object then move the camera back.

如果我为我的播放器禁用 isTrigger 那么它将无法运行通过我需要的其他对象,通过.

If I disable isTrigger for my player then it won't be able to go through the other objects which I need it, to go through.

这根本不是问题.您可以使用图层使 Unity 设置哪些碰撞器可以与另一个碰撞器发生碰撞.只需禁用 isTrigger 然后使用:

This isn't a problem at-all. You can use layers to make Unity set which colliders can collider with another. Just disable the isTrigger then use:

对于 2D:

Physics2D.IgnoreCollision(yourFirstCollider, yourOtherCollider, true);

Physics2D.IgnoreLayerCollision(yourLayer, yourOtherLayer, true)

对于 3D:

Physics.IgnoreCollision(yourFirstCollider, yourOtherCollider, true)

Physics.IgnoreLayerCollision(yourLayer, yourOtherLayer, true);

这将让玩家不会穿过地板,而是穿过你想要的任何其他物体.您也可以从编辑器设置中执行此操作... Edit --> 项目设置 --> Physics --> 或 编辑 --> 项目设置 --> Physics 2D

This will let the player not go through the floor but go through any other Objects you want. You can also do this from the Editor Settings... Edit --> Project Settings --> Physics --> or Edit --> Project Settings --> Physics 2D

玩家一旦接触到任何东西就应该死,所以我不知道如何处理这个

the player is supposed to die once it comes in contact with anything, so I don't know how to approach this

这与问题无关,但 OnCollisionEnter2D 用于检测碰撞.您可以在播放器上调用 Destroy.

This is unrelated to the problem but OnCollisionEnter2D is used to detect collsion. You can call Destroy on the player.

void OnCollisionEnter2D(Collision2D collision)
{
    Destroy(player);
}

<小时>

如果您还需要检测玩家何时接触其他碰撞器但不希望它们实际发生碰撞,那么您可以执行我上面描述的操作,然后将带有碰撞器的子对象添加到玩家.这些子对象将具有 isTrigger 启用.然后,您可以使用 OnTriggerEnter 函数来检测这些不是地板的对象之间何时发生碰撞.

If you also need to detect when the player touches other colliders but don't want them to actually collider then you can do what I described above and then add child Objects with collders to player. These Child Objects will have isTrigger enabled. You can then use thee OnTriggerEnter function to detect when there is a collision between those objects that's not a floor.

void OnTriggerEnter(Collider other)
{

}

这篇关于玩家从地板上掉下来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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