碰撞后立即停止刚体运动/旋转
我希望我的球体从一个位置跳到另一个位置但不希望它随后翻译。 我无法弄清楚如何做到这一点。 这是我的代码:
void Update() { if (!thrown && ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) || Input.GetMouseButtonDown(0))) { rb.isKinematic = false; rb.AddForce(new Vector3(0.0f, 15.0f, 5.0f) ); thrown = true; } }
有很多方法可以让对象在碰撞后立即停止。 我会给你两种方式:
方法1 :
当您检测到碰撞时,将Rigidbody
的速度设置为0
。
如果对象也在旋转,也将angularVelocity
设置为0
。
void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Player")) { Rigidbody rbdy = collision.gameObject.GetComponent(); //Stop Moving/Translating rbdy.velocity = Vector3.zero; //Stop rotating rbdy.angularVelocity = Vector3.zero; } }
方法2 :
使用物理材料控制碰撞时的摩擦力。
转到资产 > 创建 > 物理材料
将Bounciness更改为0
。
将动态和静态摩擦力更改为等于或大于1
值。
然后将其连接到Collider
上的Material
插槽。