fix: presure plate when the head is on it and pick up

This commit is contained in:
Antoine Papillon
2026-03-13 09:49:50 +01:00
parent 0fea90a480
commit 44d3ef02a3
2 changed files with 1194 additions and 34603 deletions

View File

@@ -20,6 +20,7 @@ public class PressurePlateButton : MonoBehaviour
public UnityEvent OnReleased;
private readonly HashSet<Collider> m_validCollidersOnPlate = new HashSet<Collider>();
private readonly HashSet<Collider> m_stayedThisPhysicsFrame = new HashSet<Collider>();
private bool m_isPressed;
private void Reset()
@@ -42,8 +43,16 @@ public class PressurePlateButton : MonoBehaviour
}
}
private void OnTriggerStay(Collider other)
{
if (IsValidActivator(other))
m_stayedThisPhysicsFrame.Add(other);
}
private void OnTriggerExit(Collider other)
{
m_stayedThisPhysicsFrame.Remove(other);
if (!m_validCollidersOnPlate.Remove(other))
return;
@@ -54,6 +63,26 @@ public class PressurePlateButton : MonoBehaviour
}
}
private void FixedUpdate()
{
if (m_validCollidersOnPlate.Count == 0)
{
m_stayedThisPhysicsFrame.Clear();
return;
}
m_validCollidersOnPlate.RemoveWhere(c => c == null || !c.enabled || !c.gameObject.activeInHierarchy);
m_validCollidersOnPlate.IntersectWith(m_stayedThisPhysicsFrame);
m_stayedThisPhysicsFrame.Clear();
if (m_validCollidersOnPlate.Count == 0 && m_isPressed)
{
m_isPressed = false;
OnReleased?.Invoke();
}
}
private bool IsValidActivator(Collider other)
{
if (((1 << other.gameObject.layer) & detectionMask) == 0)

File diff suppressed because one or more lines are too long