Improved doors. This introduced ghost hand issue and some doors being hinged backwards. Working on it.

This commit is contained in:
2025-12-16 15:50:55 +02:00
parent 98526fd582
commit c999bafa22
8 changed files with 488 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
using _PROJECT.NewHandPresence;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public enum GrabbingHand
{
@@ -12,6 +13,10 @@ public class DoorHandReplacer : MonoBehaviour
{
public GameObject LeftHand;
public GameObject RightHand;
public GameObject DoorSlab;
public GameObject handle;
public float DoorClosedTolerance = 5f;
private GrabbingHand? hand = null; // nullable
private SmartHandPresence currentHand = null;
@@ -23,6 +28,10 @@ public class DoorHandReplacer : MonoBehaviour
public void ManifestDoorHand()
{
if (currentHand == null || hand == null) return;
isGrabbing = true;
switch (hand.Value)
{
@@ -38,6 +47,17 @@ public class DoorHandReplacer : MonoBehaviour
Debug.Log("Dissapearing hand");
break;
}
float doorSlabRotation = DoorSlab.transform.localRotation.y;
if (Mathf.Abs(doorSlabRotation) < Mathf.Abs(DoorClosedTolerance)) // If door is closed
{
Animator animator = handle.GetComponent<Animator>();
if (animator != null)
{
animator.SetTrigger("TurnHandle");
}
}
}
public void DeManifestDoorHand()
@@ -50,6 +70,22 @@ public class DoorHandReplacer : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
if (isGrabbing && other.GetComponentInParent<HandPresencePhysics>() != null) {
if (other.gameObject.name.Contains("left", System.StringComparison.OrdinalIgnoreCase))
{
if (hand == GrabbingHand.Left) DeManifestDoorHand();
isGrabbing = false;
return;
}
else if (other.gameObject.name.Contains("right", System.StringComparison.OrdinalIgnoreCase))
{
if (hand == GrabbingHand.Right) DeManifestDoorHand();
isGrabbing = false;
return;
}
}
if (isGrabbing) return;
// IMPORTANT: in case hands have multiple colliders
@@ -104,5 +140,7 @@ public class DoorHandReplacer : MonoBehaviour
}
}
}