设置相关功能

This commit is contained in:
2025-05-30 20:38:41 +08:00
parent e9ad74b3ea
commit d152b5d000
223 changed files with 793 additions and 38907 deletions

View File

@@ -13,6 +13,11 @@ namespace NBF
_rigidbody = GetComponent<Rigidbody>();
}
private void LateUpdate()
{
}
private void FixedUpdate()
{
if (!target) return;

View File

@@ -21,10 +21,10 @@ namespace NBF
private bool _isRun;
public LookAtIK lookAtIK; // 挂在背部上的 LookAtIK 脚本
public float aimDistance = 1.5f; // 目标点离相机多远
private Transform lookTarget; // 实际目标点
[Header("限制角度(单位:度)")] public float maxUpAngle = 20f; // 相机抬头最多20°
public float maxDownAngle = 40f; // 相机低头最多40°
@@ -54,7 +54,7 @@ namespace NBF
InputManager.OnPlayerCanceled += OnPlayerCanceled;
InputManager.OnPlayerPerformed += OnPlayerPerformed;
lookAtIK = GetComponent<LookAtIK>();
lookTarget = new GameObject("SpineLookTarget").transform;
lookTarget.SetParent(_player.transform);
@@ -169,20 +169,22 @@ namespace NBF
var cameraTransform = BaseCamera.Main.transform;
Vector3 cameraForward = cameraTransform.forward;
Vector3 flatForward = Vector3.ProjectOnPlane(cameraForward, Vector3.up).normalized;
// 获取相机 pitch 角度(负值是上看,正值是下看)
float pitchAngle = Vector3.SignedAngle(flatForward, cameraForward, cameraTransform.right);
// 限制 pitch 角度
pitchAngle = Mathf.Clamp(pitchAngle, -maxUpAngle, maxDownAngle);
// 重新构造限制后的目标方向
Quaternion limitedPitch = Quaternion.AngleAxis(pitchAngle, cameraTransform.right);
Vector3 limitedDirection = limitedPitch * flatForward;
// 设置目标点
lookTarget.position = cameraTransform.position + limitedDirection * aimDistance;
lookAtIK.solver.target = lookTarget;
//
// lookAtIK.
}
#endregion