我正在嘗試構建一個破磚的遊戲,並且我想根據球擊中槳的位置瞄準球。例如,如果球碰撞槳的右邊緣,它應該向右(和向上)移動。 假設球拍有一個盒子(或膠囊)對撞球,球有一個球形對撞球,我該怎麼做? 感謝您的幫助!統一 - 如何獲得觸發碰撞角度進入?
而且我想獲得墊的速度。下面的代碼返回0,任何想法爲什麼?
function OnTriggerEnter(other:Collider)
{
if(other.rigidbody){
V_pad=other.rigidbody.velocity;
//Here it returns (0,0,0) , also tried other.attachedRigidbody
}
if(other.name=="Pad"){
rigidbody.velocity =
Vector3(rigidbody.velocity.x, Mathf.Abs(rigidbody.velocity.y + V_pad),0);
//this part executes but with V_pad.y=0
}
}
謝謝,但我在OnTriggerEnter(c:collider)處理碰撞,我無法獲得c.contacts [0],有什麼辦法可以將碰撞轉換爲碰撞? – void
看到我的編輯替代:-) –
col.ClosestPointOnBounds(transform.position)爲我做了詭計,謝謝! :) – LiranNis