之前学习通过修改Body Type的选项来控制小鸟飞出速度时遇到的疑问,两种实现方式为什么得到不一样的结果? 教程里老师讲的不够详细,自行进行了对比。可以发现,在启用kinematic时,会关闭[Mass]、[Linear Drag]、[Angular Drag]、[Gravity Scale]。
然后查阅了一下官方指南
Mass 定义 2D 刚体的质量。如果已选中 Use Auto Mass,此属性将显示灰色。 Linear Drag 一种会影响位置移动的阻力系数。 Angular Drag 一种会影响旋转移动的阻力系数。 Gravity Scale 定义游戏对象受重力影响的程度。
Body Type:Dynamic
A Dynamic Rigidbody 2D is designed to move under simulation. It has the full set of properties available to it such as finite mass and drag, and is affected by gravity and forces. A Dynamic body will collide with every other body type, and is the most interactive of body types. This is the default body type for a Rigidbody 2D, because it is the most common body type for things that need to move. It’s also the most performance-expensive body type, because of its dynamic nature and interactivity with everything around it. All Rigidbody 2D properties are available with this body type.
Body Type: Kinematic
A Kinematic Rigidbody 2D is designed to move under simulation, but only under very explicit user control. While a Dynamic Rigidbody 2D is affected by gravity and forces, a Kinematic Rigidbody 2D isn’t. For this reason, it is fast and has a lower demand on system resources than a Dynamic Rigidbody 2D. Kinematic Rigidbody 2D is designed to be repositioned explicitly via Rigidbody2D.MovePosition or Rigidbody2D.MoveRotation. Use physics queries to detect collisions, and scripts to decide where and how the Rigidbody 2D should move.
在按下鼠标时,dynamic模式的小鸟是否已经通过计算具有速度;而按下鼠标启用kinematic模式,松开鼠标禁用kinematic的小鸟初速度为0,设置0.2s后禁用弹簧,导致小鸟的加速阶段仅有0.2s。因此,这样实现小鸟飞出的脚本会得到较慢的速度。
|