This commit is contained in:
MuHua-123
2025-03-11 23:45:41 +08:00
parent a86e32c89e
commit 9f56eff9c0
48 changed files with 319 additions and 158 deletions
@@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace MuHua {
public class ControllerPlayer : MonoBehaviour {
public Transform cameraController; // 相机对象
public CharacterPlayer character;
private Vector2 moveInput;
private void Update() {
if (moveInput == Vector2.zero) { return; }
// 获取相机的前向和右向
Vector3 cameraForward = cameraController.transform.forward;
Vector3 cameraRight = cameraController.transform.right;
// 忽略相机的y轴
cameraForward.y = 0;
cameraRight.y = 0;
// 归一化向量
cameraForward.Normalize();
cameraRight.Normalize();
// 计算相对于相机的移动方向
Vector3 moveDirection = (cameraForward * moveInput.y + cameraRight * moveInput.x).normalized;
// 相对于玩家的移动方向
Vector3 position = character.transform.position + new Vector3(moveDirection.x, 0, moveDirection.z) * 0.5f;
KinesisMove kinesis = new KinesisMove(character, position);
character.Transitionkinesis(kinesis);
}
#region
public void OnMove(InputValue inputValue) {
// 获取移动输入
moveInput = inputValue.Get<Vector2>();
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 73bafdf07b08fc246ab173a5e555629e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: