简体   繁体   English

玩家在 Unity 3D 中穿墙

[英]Player is moving through the Wall in Unity 3D

I am making a simple game where the Player moves only Horizontally and the Enemies spawn from front.我正在制作一个简单的游戏,玩家只能水平移动,而敌人则从前面产生。 I created a Wall at the Left and Right side of the Player.我在播放器的左侧和右侧创建了一个墙。 But, Player keeps going through the Wall even when I have added Rigidbody component to Walls and Player.但是,即使我在 Walls 和 Player 中添加了 Rigidbody 组件,Player 也会继续穿墙。 I used Cube gameobject to make a wall.我用立方体游戏对象制作了一堵墙。 Please help.请帮忙。 Thank you!谢谢!

  1. Do you have collider on walls and on player?你在墙上和播放器上有碰撞器吗?
  2. If walls and player have colliders, check are theese colliders turned on and not triggers.如果墙壁和玩家有碰撞器,请检查这些碰撞器是否已打开而不是触发器。 (They should be turned on and checkbox "Is trigger" should be false) (它们应该被打开并且复选框“Is trigger”应该是假的)
  3. If previous steps completed and it still doesn't work, check Edit -> Project Settings -> Physics -> Layer collision matrix.如果之前的步骤已完成但仍无法正常工作,请检查编辑 -> 项目设置 -> 物理 -> 层碰撞矩阵。 And make sure that walls' layer collides with player's layer并确保墙壁的图层与玩家的图层碰撞

I have NavMesh agent on my player and what helped me:我的播放器上有 NavMesh 代理,这对我有什么帮助:

  1. Mark walls (and other static objects) as static in inspector在检查器中将墙壁(和其他 static 对象)标记为 static
  2. Go to Window->AI->Navigation and bake the scene Go 到 Window->AI->Navigation 和烘焙场景

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM