设置相关功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
public class ArmTest : MonoBehaviour
|
||||
@@ -8,28 +9,50 @@ public class ArmTest : MonoBehaviour
|
||||
public Transform targetTransform;
|
||||
// public float Value;
|
||||
|
||||
private Quaternion initialCameraRotation;
|
||||
private Quaternion initialLocalRotation;
|
||||
private Quaternion initialRelativeRotation;
|
||||
|
||||
|
||||
[SerializeField] private float smoothSpeed = 5f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// target = transform.localEulerAngles;
|
||||
|
||||
// 记录初始状态
|
||||
initialCameraRotation = BaseCamera.Main.transform.rotation;
|
||||
initialLocalRotation = transform.localRotation;
|
||||
|
||||
// 计算物体相对于相机的旋转
|
||||
initialRelativeRotation = Quaternion.Inverse(initialCameraRotation) * transform.rotation;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private Quaternion lastCameraRotation;
|
||||
[SerializeField] private float angleThreshold = 0.1f; // 角度阈值(度)
|
||||
private bool needsUpdate;
|
||||
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!targetTransform) return;
|
||||
// transform.localEulerAngles = target;
|
||||
targetTransform.localRotation = Quaternion.Euler(target.x, target.y, target.z);
|
||||
//我草拟吗。transform.localEulerAngle = target;
|
||||
//wo shi da sha bi. ArmTest Monobehaviour
|
||||
//我草拟大爷的。transofrm.localEulerAngles = target;
|
||||
Debug.LogError(targetTransform.rotation);
|
||||
|
||||
// void LateUpdate()
|
||||
// {
|
||||
// Transform shoulder = animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
|
||||
// if (shoulder != null)
|
||||
// {
|
||||
// // 局部旋转叠加(例如绕Z轴微调)
|
||||
// shoulder.localRotation *= Quaternion.Euler(0, 0, shoulderOffsetAngle);
|
||||
// }
|
||||
// }
|
||||
|
||||
// 计算物体应有的世界旋转
|
||||
Quaternion targetWorldRotation = BaseCamera.Main.transform.rotation * initialRelativeRotation;
|
||||
|
||||
// 转换为本地旋转(如果是子物体)
|
||||
transform.localRotation = Quaternion.Inverse(transform.parent.rotation) * targetWorldRotation;
|
||||
|
||||
|
||||
// // 使用Lerp平滑过渡
|
||||
// transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(target.x, target.y, target.z), smoothSpeed * Time.deltaTime);
|
||||
// // targetTransform.localRotation = Quaternion.Euler(target.x, target.y, target.z);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user