原本是用
character.isGrounded 來判斷
但是自己使用的感想覺得不是非常準確
常常偵測不到
(當然可能是某個條件未滿足所造成的)
參考了這兩篇文章後
http://answers.unity3d.com/questions/424047/character-controller-isgroundedfalse-while-moving.html
http://answers.unity3d.com/questions/196381/how-do-i-check-if-my-rigidbody-player-is-grounded.html
整理出以下的方法
用Raycast去偵測
確實能work
參考看看^^
private float distToGround;
bool IsGrounded() {
//return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f);
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 1.1f);
}
原本網友是用0.1f 但是我跑了以後偵測不到
可能跟每個人的collider大小有關
我調到1.1f後就能正常偵測了^^
-Vector3.up = (0,-1,0)
回覆刪除等於人物今天走到哪都是往世界座標(0,-1,0)的位置做射線檢測
把它改成 -transform.up才是正確的