fix: update SlidingDoor to use parent space for slide vector calculations
This commit is contained in:
@@ -7,7 +7,7 @@ public class SlidingDoor : MonoBehaviour
|
|||||||
public enum SlideDirection { Positive = 1, Negative = -1 }
|
public enum SlideDirection { Positive = 1, Negative = -1 }
|
||||||
|
|
||||||
[Header("Slide Settings")]
|
[Header("Slide Settings")]
|
||||||
[Tooltip("Local axis the door slides along.")]
|
[Tooltip("Axis in parent space (or world space if no parent) the door slides along.")]
|
||||||
[SerializeField] private SlideAxis axis = SlideAxis.X;
|
[SerializeField] private SlideAxis axis = SlideAxis.X;
|
||||||
|
|
||||||
[Tooltip("Which way along the axis the door opens.")]
|
[Tooltip("Which way along the axis the door opens.")]
|
||||||
@@ -36,7 +36,7 @@ public class SlidingDoor : MonoBehaviour
|
|||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
m_closedPos = transform.localPosition;
|
m_closedPos = transform.localPosition;
|
||||||
m_openPos = m_closedPos + GetSlideVector() * slideDistance;
|
m_openPos = m_closedPos + GetParentSpaceSlideVector() * slideDistance;
|
||||||
|
|
||||||
if (startOpen)
|
if (startOpen)
|
||||||
{
|
{
|
||||||
@@ -86,7 +86,7 @@ public class SlidingDoor : MonoBehaviour
|
|||||||
Open();
|
Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3 GetSlideVector()
|
private Vector3 GetParentSpaceSlideVector()
|
||||||
{
|
{
|
||||||
float sign = (float)direction;
|
float sign = (float)direction;
|
||||||
return axis switch
|
return axis switch
|
||||||
@@ -98,14 +98,19 @@ public class SlidingDoor : MonoBehaviour
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Vector3 GetWorldSpaceSlideVector()
|
||||||
|
{
|
||||||
|
return transform.parent != null
|
||||||
|
? transform.parent.TransformDirection(GetParentSpaceSlideVector()).normalized
|
||||||
|
: GetParentSpaceSlideVector().normalized;
|
||||||
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
private void OnDrawGizmos()
|
private void OnDrawGizmos()
|
||||||
{
|
{
|
||||||
Vector3 worldClosed = transform.parent != null
|
Vector3 worldClosed = transform.position;
|
||||||
? transform.parent.TransformPoint(transform.localPosition)
|
|
||||||
: transform.position;
|
|
||||||
|
|
||||||
Vector3 slideVec = transform.TransformDirection(GetSlideVector()) * slideDistance;
|
Vector3 slideVec = GetWorldSpaceSlideVector() * slideDistance;
|
||||||
Gizmos.color = Color.cyan;
|
Gizmos.color = Color.cyan;
|
||||||
Gizmos.DrawLine(worldClosed, worldClosed + slideVec);
|
Gizmos.DrawLine(worldClosed, worldClosed + slideVec);
|
||||||
Gizmos.DrawWireSphere(worldClosed + slideVec, 0.08f);
|
Gizmos.DrawWireSphere(worldClosed + slideVec, 0.08f);
|
||||||
|
|||||||
Reference in New Issue
Block a user