Unity simuliert den Kamera-Gimbal-Effekt – die angegebene Achse des Objekts wird vom übergeordneten Knoten nicht beeinflusst

Der Rotationswert der Weltkoordinaten der angegebenen Achse des Objekts ändert sich nicht mit dem übergeordneten Knoten

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);
    }
}

おすすめ

転載: blog.csdn.net/weixin_45023328/article/details/128845535