物体指定轴的世界坐标旋转值不随父节点改变
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Camera Stabilizer
/// </summary>
public class Stabilizer : MonoBehaviour
{
/// <summary>
/// Stable axis
/// </summary>
[Header("Stable axis")]
public bool x = true;
public bool y;
public bool z = true;
/// <summary>
/// Default Rotation
/// </summary>
Quaternion mR;
/// <summary>
/// parent
/// </summary>
Transform P;
void Start()
{
mR = Quaternion.identity;
P = transform.parent;
}
void Update()
{
transform.rotation = new Quaternion(x ? mR.x : P.rotation.x, y ? mR.y : P.rotation.y, z ? mR.z : P.rotation.z, mR.w);
}
}