崩溃系统Unity3d

时间:2017-12-14 09:01:03

标签: unity3d crash physics

我在unity3d制作汽车游戏,我有城市,汽车,路灯等。我想让它可以破坏,就像在GTA中一样。现在它的工作应该是这样,但问题在于某些物体的阻力,例如交通信号灯或灯具,混凝土的物体。

这是描述它的图片: enter image description here

这是我的剧本,非常简单,低速工作(<60-70kmh):

private void OnCollisionEnter(Collision collision)
{
    PlayerSpeed = gameObject.GetComponent<Rigidbody>().velocity.magnitude * 3.6f;
    PlayerMass = gameObject.GetComponent<Rigidbody>().mass;
    PlayerKineticEnergy = (PlayerMass * PlayerSpeed * PlayerSpeed) / 2;

    if (PlayerKineticEnergy > 900000.0f)
    {
        collision.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
        StreetBehaviour = collision.gameObject.GetComponent<Street_Asc_Behaviour>();
        CollisionSpeed = Mathf.Sqrt((2 * 900000) / (PlayerMass));
        gameObject.GetComponent<Rigidbody>().AddForce(transform.forward * (-CollisionSpeed * StreetBehaviour.ObjectResistance), ForceMode.Impulse);
    }
}

正如你所看到的,我在刚体中使用冻结位置和旋转,它在低速下工作得非常好。在高速时它不会检测到碰撞。

所以,如果你有更好的一个,那就太好了:)

由于

0 个答案:

没有答案
相关问题