Panda3D手册:碰撞障碍

A CollisionTraverser object performs the actual work of checking all solid objects for collisions. Normally, you will create a single CollisionTraverser object and assign it to base.cTrav; this traverser will automatically be run every frame. It is also possible to create additional CollisionTraversers if you have unusual needs; for instance, to run a second pass over a subset of the geometry. If you create additional CollisionTraversers, you must run them yourself.
一个 CollisionTraverser 物体检查所有固体的碰撞。通常,您需要建立一个 CollisionTraverser 物体,并且分配给 base.cTrav;这样障碍物会在每一帧都进行检测。如果需要,它也可以创建附加的 CollisionTraverser ;例如,进行二次碰撞测试。如果您建立了附加的 CollisionTraverser,您要让它自己运行起来。

The CollisionTraverser maintains a list of the active objects in the world, sometimes called the "colliders" or "from objects". The remaining collidable objects in the world that are not added to a CollisionTraverser are the "into objects". Each of the "from objects" is tested for collisions with all other objects in the world, including the other from objects as well as the into objects.
CollisionTraverser 维护一个同台的列表,有时称为 “碰撞” 或者 “from 物体” 。其余的没有加入 CollisionTraverser 的 collidable 物体叫做 “into 物体” 。障碍物会检测世界中的每一个 “from 物体”,包括来自其他 into 物体中的 from 物体。

Note that it is up to you to decide how to divide the world into "from objects" and "into objects". Typically, the from objects are the moving objects in the scene, and the static objects like walls and floors are into objects, but the collision system does not require this; it is perfectly legitimate for a from object to remain completely still while an into object moves into it, and the collision will still be detected.
注意,哪个是 “from 物体” 哪个是 “into 物体” 都是由您来决定的。就习惯而言,from 物体是可以移动的物体,像墙壁和地板之类的静态物体一般是 into 物体,但是碰撞系统没有硬性规定这些区别,from 也可以是静止的物体,当 into 物体碰到 from 物体时,碰撞检测也能检测出来。

It is a good idea for performance reasons to minimize the number of from objects in a particular scene. For instance, the user's avatar is typically a from object; in many cases, it may be the only from object required--all of the other objects in the scene, including the walls, floors, and other avatars, might be simply into objects. If your game involves bullets that need to test for collisions with the other avatars, you will need to make either the bullets or the other avatars be from objects, but probably not both.
就性能而言,应尽量减少场景中的 from 物体。例如,玩家控制的游戏角色通常是 from 物体;在许多情况下,from 对象要碰撞场景中的所有对象,包括墙、地板和其他角色,也许只有一个 into 物体。如果您的游戏要用到子弹,您还需要测试子弹和其他角色的碰撞,但是不能同时使用。

In order to add a from object to the CollisionTraverser, you must first create a CollisionHandler that defines the action to take when the collision is detected; then you pass the NodePath for your from object, and its CollisionHandler, to addCollider.
要为 from 物体增加附加的 CollisionTraverser,您必须首先建立一个 CollisionHandler ,它会在检测到碰撞时进行操作;使用 addCollider 命令,通过您的 from 物体的 NodePath 来添加 CollisionHandler 。

traverser = CollisionTraverser('traverser name')
base.cTrav = traverser
traverser.addCollider(fromObject, handler)

You only need to add the "from" objects to your traverser! Don't try to add the "into" objects to the CollisionTraverser. Adding an object to a CollisionTraverser makes it a "from" object. On the other hand, every object that you put in the scene graph, whether it is added to a CollisionTraverser or not, is automatically an "into" object.
您只需要为障碍物添加一个 “from” 物体 不要尝试为障碍物添加 “into” 物体。将一个物体添加到 CollisionTraverser 的同时,这个物体就成为了 “from” 物体。另外,场景中的每一个物体,不论它是否被添加到 CollisionTraverser 中,都会自动成为 “into” 物体。

Note that all of your "from" objects are typically "into" objects too (because they are in the scene graph), although you may choose to make them not behave as into objects by setting their CollideMask to zero.
注意所有的 “from” 物体也同时是 “into” 物体(因为在场景中的都是 into 物体),虽然您也可以将它们的 CollideMask 设为零,让它们不进行碰撞检测。

The CollisionTraverser can visually show the collisions that are occurring by using the following line of code:
CollisionTraverser 可以显示障碍物,您需要使用下面的代码:

collisionTraverser.showCollisions(render)