Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Features/Extensions/RoomExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NorthwoodLib.Pools;
using ProjectMER.Features.Serializable;
using UnityEngine;
using Random = UnityEngine.Random;

namespace ProjectMER.Features.Extensions;

Expand Down Expand Up @@ -48,4 +49,24 @@ public static Quaternion GetAbsoluteRotation(this Room? room, Vector3 eulerAngle

return room.Transform.rotation * Quaternion.Euler(eulerAngles);
}

public static Vector3 GetRelativePosition(this Room room, Vector3 position)
=> room.Transform.InverseTransformPoint(position);

public static Quaternion GetRelativeRotation(this Room? room, Vector3 rotation)
{
if (Mathf.Approximately(rotation.x, -1f))
rotation.x = Random.Range(0f, 360f);

if (Mathf.Approximately(rotation.y, -1f))
rotation.y = Random.Range(0f, 360f);

if (Mathf.Approximately(rotation.z, -1f))
rotation.z = Random.Range(0f, 360f);

if (room == null)
return Quaternion.Euler(rotation);

return room.Zone == FacilityZone.Surface ? Quaternion.Euler(rotation) : room.Transform.rotation * Quaternion.Euler(rotation);
}
}