當我為我的角色添加一個Character Controller組件時,我的角色會在空中上升 0.08 個單位。這只會在我開始移動時發生。對撞機似乎處于正確的位置。
這是帶有Character Controller組件的角色的螢屏截圖:

我的角色設定截圖:

我的運動代碼:
[SerializeField] private Transform _orientation;
private CharacterController _controller;
private float xInput;
private float yInput;
private Vector3 _moveDirection;
private float rotationSpeed = 10f;
private float speed = 5f;
private void Awake()
{
_controller = GetComponent<CharacterController>();
}
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
xInput = Input.GetAxis("Horizontal");
yInput = Input.GetAxis("Vertical");
_moveDirection = _orientation.forward * yInput _orientation.right * xInput;
RotatePlayerToCameraView();
Move(_moveDirection);
}
private void RotatePlayerToCameraView()
{
Vector3 viewDirection = transform.position - new Vector3(_orientation.position.x, transform.position.y, _orientation.position.z);
_orientation.forward = viewDirection.normalized; // понять зачем это и как вообще
gameObject.transform.forward = Vector3.Slerp(gameObject.transform.forward, viewDirection.normalized, Time.deltaTime * rotationSpeed);
}
private void Move(Vector3 moveDirection)
{
float scaledMoveSpeed = speed * Time.deltaTime;
moveDirection = new Vector3(moveDirection.x, 0, moveDirection.z);
_controller.Move(moveDirection * scaledMoveSpeed);
}
uj5u.com熱心網友回復:
skin width: 0.08角色控制器和我的角色0.08 units問題之間似乎存在相關性。
查看CharacterController.skinWidth Unity 檔案:
指定角色周圍的皮膚,物理引擎將在其中生成接觸。
看起來物理引擎正在使用整體接觸的寬度。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/534998.html
標籤:C#unity3d
