获得碰撞接触力

时间:2016-04-03 16:06:07

标签: c# unity3d game-physics

有没有办法获得碰撞的接触力?我试图通过OnCollisionEnter()方法获得速度来做到这一点。但它在接触后给出速度,这对我没用。

1 个答案:

答案 0 :(得分:3)

Absolutely! If you check the Unity docs, there is a handy variable called Collision.impulse. This was only introduced recently in Unity 5.2 so if you haven't updated yet, consider doing so. (Otherwise, you'll be forced to use one of the now-deprecated solutions floating on the internet instead.)

Based on the documentation, to get the force applied you would just divide this value by the last frame's Time.fixedDeltaTime (since in physics, impulse = force * time):

void OnCollisionEnter(Collision col) {
    Vector3 collisionForce = col.impulse / Time.fixedDeltaTime;
    // And now you can use it for your calculations!
}