private void HandleMovement() { float moveX = 0f; float moveY = 0f; if (Input.GetKey(KeyCode.W)) { moveY = +1f; } if (Input.GetKey(KeyCode.S)) { moveY = -1f; } if (Input.GetKey(KeyCode.A)) { moveX = -1f; } if (Input.GetKey(KeyCode.D)) { moveX = +1f; } Vector3 moveDir = new Vector3(moveX, moveY).normalized; bool isIdle = moveX == 0 && moveY == 0; if (isIdle) { playerBase.PlayIdleAnim(); } else { playerBase.PlayMoveAnim(moveDir); transform.position += moveDir * SPEED * Time.deltaTime; } }
private void HandleMovement() { if (pathVectorList != null) { Vector3 targetPosition = pathVectorList[currentPathIndex]; if (Vector3.Distance(transform.position, targetPosition) > 1f) { Vector3 moveDir = (targetPosition - transform.position).normalized; float distanceBefore = Vector3.Distance(transform.position, targetPosition); characterBase.PlayMoveAnim(moveDir); transform.position = transform.position + moveDir * SPEED * Time.deltaTime; } else { currentPathIndex++; if (currentPathIndex >= pathVectorList.Count) { StopMoving(); characterBase.PlayIdleAnim(); } } } else { characterBase.PlayIdleAnim(); } }
public void PlayMoveAnim(Vector3 moveDir) { characterAimBase.PlayMoveAnim(moveDir); playerBase.PlayMoveAnim(moveDir); }