Created
April 15, 2014 14:59
-
-
Save smallrice45/10739513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 著地判斷 | |
public LayerMask isGroundedSlopeLayer; | |
public float isGroundedSlopeDis = 0.5f; | |
// 如果傳入 !isJumped 判斷是否在地面,於角色腳下斜後方打出射線來判斷 | |
// 如果在斜坡上則返回true | |
// 如果不在斜坡上且角色控制器也不在地面則返回false | |
// 如果傳入 isJumped 判斷是否在斜面上,避免在斜面上無法操作一些動作或修正 | |
// ex. 由於跳躍高度不夠快而黏在樓梯、由於樓梯上的重力不足而出現浮空狀態 | |
bool isGroundedSlope(bool isJumped) | |
{ | |
Vector3 playerFootPos = mMovement.mTransform.position; // 設定角色足部座標位置,1.6m的角色 | |
playerFootPos.y = playerFootPos.y - 0.5f; // 大概中心y軸-0.5m約略膝蓋位置 | |
Vector3 playerFootAngle = -mMovement.direction; // 設定角色足後方角度,反轉正前方為後方 | |
playerFootAngle.y = -1.0f; // 將y軸修正為-1約略鞋後下方45度 | |
float rayCastLength = playerFootAngle.magnitude * isGroundedSlopeDis; // 將長度轉換為向量長度方便讓Raycast設定長度 | |
Debug.DrawRay ( playerFootPos, playerFootAngle * isGroundedSlopeDis, Color.green); // 以上面修正的角度位置打出編輯器可看到的綠色射線 | |
if (Physics.Raycast( playerFootPos , playerFootAngle,out mMovement.hit , rayCastLength, isGroundedSlopeLayer)) | |
{ | |
return true; | |
}else{ | |
if (mMovement.mController.isGrounded && isJumped){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment