Unity人物垂直地面的實現

void Update () {
        RaycastHit hit;
        Vector3 point_dir = transform.TransformDirection(Vector3.down);
        if(Physics.Raycast(transform.position,point_dir,out hit,1000f,LayerMask.GetMask("Ground")))
        {
            Quaternion nextRot = Quaternion.LookRotation(Vector3.Cross(hit.normal,Vector3.Cross(transform.forward,hit.normal)),hit.normal);
            transform.rotation = Quaternion.Lerp(transform.rotation,nextRot,0.1f);
        }
	}

由人物的腳下發射射線,檢測地面所在的層級,將人物的旋轉置爲垂直地面後的旋轉

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章