Fixed player location calculation via camera trigger collider

This commit is contained in:
2025-10-17 17:17:41 +03:00
parent 013ed4944c
commit 2e61259ebe
40 changed files with 7649 additions and 1707 deletions

View File

@@ -4380,6 +4380,7 @@ GameObject:
- component: {fileID: 1248243081272065818}
- component: {fileID: 7904742026328308208}
- component: {fileID: 438034309889585932}
- component: {fileID: 5359875513008250733}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@@ -4630,6 +4631,27 @@ MonoBehaviour:
m_EditorClassIdentifier:
nonRigidbodyVelocity: 0
attenuationObject: {fileID: 0}
--- !u!135 &5359875513008250733
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6810398627900972352}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Radius: 0.1
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &6839907377310123617
GameObject:
m_ObjectHideFlags: 0

View File

@@ -322,7 +322,7 @@ MonoBehaviour:
Params: []
OverrideAttenuation: 0
OverrideMinDistance: 1
OverrideMaxDistance: 20
OverrideMaxDistance: 30
--- !u!1 &6014189720456933605
GameObject:
m_ObjectHideFlags: 0
@@ -441,6 +441,7 @@ GameObject:
- component: {fileID: 2501038558182094805}
- component: {fileID: 8089229340536715967}
- component: {fileID: 7305371174892849299}
- component: {fileID: 3068203956378754948}
m_Layer: 0
m_Name: Portal
m_TagString: Untagged
@@ -560,3 +561,30 @@ MonoBehaviour:
occlusionPortal: {fileID: 0}
_shouldTeleport: 1
teleportationProvider: {fileID: 0}
--- !u!54 &3068203956378754948
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8507770192447112443}
serializedVersion: 4
m_Mass: 0.001
m_Drag: 0
m_AngularDrag: 0
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_ImplicitCom: 0
m_ImplicitTensor: 0
m_UseGravity: 0
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using Unity.XR.CoreUtils;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.XR;
using UnityEngine.XR.Interaction.Toolkit;
@@ -34,7 +35,11 @@ public class StencilPortal : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
if (other.GetComponent<XROrigin>() == null) return;
//Debug.Log("Something entered portal");
if (other.GetComponent<UniversalAdditionalCameraData>() == null) return;
//if (other.GetComponent<XROrigin>() == null) return;
XROrigin player = other.GetComponentInParent<XROrigin>();
if (player == null) return;
if (occlusionPortal != null)
{
@@ -55,8 +60,8 @@ public class StencilPortal : MonoBehaviour
if (teleportationProvider != null)
{
Vector3 targetPosition = TransformPositionBetweenPortals(this, targetPortal, other.transform.position);
Quaternion targetRotation = TransformRotationBetweenPortals(this, targetPortal, other.transform.rotation);
Vector3 targetPosition = TransformPositionBetweenPortals(this, targetPortal, player.transform.position);
Quaternion targetRotation = TransformRotationBetweenPortals(this, targetPortal, player.transform.rotation);
TeleportRequest request = new TeleportRequest
{
@@ -69,13 +74,13 @@ public class StencilPortal : MonoBehaviour
teleportationProvider.QueueTeleportRequest(request);
other.transform.rotation = TransformRotationBetweenPortals(this, targetPortal, other.transform.rotation);
player.transform.rotation = TransformRotationBetweenPortals(this, targetPortal, player.transform.rotation);
}
else
{
Debug.LogWarning("TeleportationProvider is not assigned!", this);
other.transform.position = TransformPositionBetweenPortals(this, targetPortal, other.transform.position);
other.transform.rotation = TransformRotationBetweenPortals(this, targetPortal, other.transform.rotation);
player.transform.position = TransformPositionBetweenPortals(this, targetPortal, player.transform.position);
player.transform.rotation = TransformRotationBetweenPortals(this, targetPortal, player.transform.rotation);
}
if (destroyAfterTeleport)