Unity3D-模拟物理完全弹性碰撞反弹

根据入射方向得到反射方向,并保留相同速率

    private Vector3 m_preVelocity = Vector3.zero;//上一帧速度

    public void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.name == "wall")
        {
            ContactPoint contactPoint = collision.contacts[0];
            Vector3 newDir = Vector3.zero;
            Vector3 curDir = transform.TransformDirection(Vector3.forward);
            newDir = Vector3.Reflect(curDir, contactPoint.normal);
            Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, newDir);
            transform.rotation = rotation;
            rigidbody.velocity = newDir.normalized * m_preVelocity.x / m_preVelocity.normalized.x;
        }

}转自http://blog.csdn.net/wsc122181582/article/details/52790317

猜你喜欢

转载自blog.csdn.net/u014635337/article/details/54900724