且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

空气曲棍球游戏 - 玩家蝙蝠经过冰球,如果移动速度太快

更新时间:2023-02-02 21:36:09

您是对的,试图连续碰撞检测(CCD)。有一些限制(尤其是在这种情况下要使用的CCD有两个移动的物体而不是一个移动物体和一个静态对象),但它是专为这种情况的。 的刚体文档进入这些约束:

You were right to try continuous collision detection (CCD). There are some constraints (especially in this case where you want to use CCD with two moving objects rather than one moving object and one static object), but it is designed for this kind of scenario. The Rigidbody documentation goes into these constraints:

设置碰撞检测模式为连续防止
刚体穿过任何静态(即非刚体)
MeshColliders。将它设置为连续动态也防止
刚体穿过设置为连续或连续动态
碰撞检测模式任何其他支持刚体。在支持盒 - ,Sphere-和
CapsuleColliders
连续碰撞检测。

Set the collision detection mode to Continuous to prevent the rigidbody from passing through any static (ie, non-rigidbody) MeshColliders. Set it to Continuous Dynamic to also prevent the rigidbody from passing through any other supported rigidbodies with collision detection mode set to Continuous or Continuous Dynamic. Continuous collision detection is supported for Box-, Sphere- and CapsuleColliders.

要综上所述,无论是冰球和桨需要被设置为连续动态,并且既需要是盒 - ,Sphere-或胶囊撞机。如果你可以让这些约束你的游戏工作,你应该能够得到连续碰撞检测,而不自己写的吧。

To sum up, both puck and paddle need to be set to Continuous Dynamic, and both need to be Box-, Sphere-, or Capsule Colliders. If you can make these constraints work for your game you should be able to get continuous collision detection without writing it yourself.

关于Unity的CCD一张纸条,值得重复:

A note about Unity's CCD that bears repeating:

注意,连续碰撞检测的目的是作为一个安全网
赶上碰撞中情况下,对象本来互相传递
,但不会提供精确物理碰撞
的结果,所以你可能还在考虑在TimeManager督察降低固定时间步长
值,使模拟更多
精确,如果您遇到的问题与快速移动的物体。

Note that continuous collision detection is intended as a safety net to catch collisions in cases where objects would otherwise pass through each other, but will not deliver physically accurate collision results, so you might still consider decreasing the fixed Time step value in the TimeManager inspector to make the simulation more precise, if you run into problems with fast moving objects.

不过,因为你是手动指定碰撞反应,可能不会成为一个问题。

But since you are manually specifying the collision reaction, that might not be an issue.