unity3d:物體尋路貼合地面,y軸與地面normal方向平行(坦克爬斜坡問題)

坦克在爬斜坡時,保持坦克是貼合地面前進
尋路掛在父物體上,控制姿態腳本掛在坦克子物體上
RaycastHit hit;
int Rmask = LayerMask.GetMask ("Terrain");
Vector3 Point_dir = transform.TransformDirection(Vector3.down);
if (Physics.Raycast(transform.position, Point_dir, out hit, 50.0f,Rmask)) {
Quaternion NextRot=Quaternion.LookRotation(Vector3.Cross(hit.normal,Vector3.Cross(transform.forward,hit.normal)),hit.normal);
transform.MoveRotation(Quaternion.Lerp(transform.rotation,NextRot,0.1f));
}
浙公網安備 33010602011771號