unity 模拟相机云台效果-物体指定轴不受父节点影响

物体指定轴的世界坐标旋转值不随父节点改变

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
今日推荐