using System.Collections; using System.Collections.Generic; using UnityEngine; using NaughtyAttributes; /// /// Utility script to fake parent an object to another /// public class CopyTransform : MonoBehaviour { #region Inspector Fields [SerializeField, BoxGroup("References")] public Transform m_target; [SerializeField, Range(0, 1)] public float m_dampening = 1; #endregion Inspector Fields #region Private Fields private Vector3 m_positionOffset; private Quaternion m_rotationOffset; #endregion Private Fields #region Getters #endregion Getters #region MonoBehaviour Functions private void Awake() { m_positionOffset = transform.position - m_target.position; m_rotationOffset = m_target.rotation * Quaternion.Inverse(transform.rotation); } /// /// OnEnable is called when the object becomes enabled and active. /// private void OnEnable() { } /// /// OnDisable is called when the behaviour becomes disabled. /// private void OnDisable() { } /// /// Update is called once per frame /// private void FixedUpdate() { Vector3 expectedPosition = m_target.position + (m_target.rotation * m_positionOffset); Quaternion expectedRotation = m_target.rotation * m_rotationOffset; transform.position = Vector3.Lerp(transform.position, expectedPosition, m_dampening); transform.rotation = Quaternion.Lerp(transform.rotation, expectedRotation, m_dampening); } #endregion MonoBehaviour Functions #region Class Functionality #endregion Class Functionality #region Editor Functions /// /// Called when the Component is created or Reset from the Inspector /// private void Reset() { //useful for finding components on creation } #endregion Editor Functions }