2017-04-02 266 views
0

我希望我的球體從一個位置跳到另一個位置,但不希望它在之後翻譯。我無法弄清楚如何做到這一點。這裏是我的代碼:在碰撞後立即停止剛體運動/旋轉

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; 
    } 
} 
+0

你是什麼意思「翻譯」?在翻譯球的地方你有更多的代碼嗎?如果是這樣,您應該添加它 – dogiordano

+0

否,但AddForce正在進行翻譯。 – solo365

+0

如果我理解得很好,你想讓球在接地後停下來嗎? – Andromelus

回答

2

有很多方法可以使對象在collison後立即停止。我給你兩條路:

方法1

當你檢測科裏森將Rigidbody0速度

如果對象也在旋轉,請將angularVelocity設置爲0

void OnCollisionEnter(Collision collision) 
{ 
    if (collision.gameObject.CompareTag("Player")) 
    { 
     Rigidbody rbdy = collision.gameObject.GetComponent<Rigidbody>(); 

     //Stop Moving/Translating 
     rbdy.velocity = Vector3.zero; 

     //Stop rotating 
     rbdy.angularVelocity = Vector3.zero; 
    } 
} 

方法2

使用物理學材料到科裏森期間控制摩擦的量。

轉到資產>創建>物理學材料

更改反彈力0

更改動態靜態摩擦到值等於或超過1

enter image description here

然後將其連接到Material插槽您Collider

enter image description here