玩家有一个使用胶囊对撞机进行连续碰撞检测的刚体.冰球还具有连续动态碰撞检测的刚体和带凸面的网格对撞机.
我尝试将固定时间步长设置为0.01,但没有效果.这是玩家运动的脚本:
void ObjectFollowCursor() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 point = ray.origin + (ray.direction * distance); Vector3 temp = point; temp.y = 0.2f; // limits player on y axis cursorObject.position = temp; }
这是冰球与玩家碰撞时的代码:
// If puck hits player if(collision.gameObject.tag == "Player") { Vector3 forceVec = this.GetComponent<Rigidbody>().velocity.normalized * hitForce; rb.AddForce(forceVec,ForceMode.Impulse); Debug.Log ("Player Hit"); }
任何帮助将非常感激.谢谢.
解决方法
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.
总而言之,冰球和桨叶都需要设置为连续动态,并且都需要是Box,Sphere或Capsule Colliders.如果您可以使这些约束适用于您的游戏,您应该能够连续碰撞检测,而无需自己编写.
有关Unity的CCD的重复说明:
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.
但由于您手动指定碰撞反应,这可能不是问题.