From 94b0d07a3ea7653940a781b5154f4153a2916890 Mon Sep 17 00:00:00 2001
From: Marius Kern <mariusskern@gmail.com>
Date: Wed, 31 Jul 2024 19:09:43 +0200
Subject: [PATCH] Triangle Rotation fixed

---
 .../FactHandling/Facts/TriangleFact2.cs          | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/TriangleFact2.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/TriangleFact2.cs
index 8676234b..86696d9d 100644
--- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/TriangleFact2.cs
+++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/TriangleFact2.cs
@@ -63,9 +63,19 @@ protected void calculate_vectors(){
 
         Position = A;
 
-        Rotation = Quaternion.LookRotation(Vector3.Cross((B - A), (C - A)), Vector3.up);
-        //Rotation = Quaternion.LookRotation(forward, new Vector3(1.0F, 0.0F, 0.0F));
-        
+        // Rotation = Quaternion.LookRotation(Vector3.Cross((B - A), (C - A)), Vector3.up);
+        // Rotation = Quaternion.LookRotation(forward, new Vector3(1.0F, 0.0F, 0.0F));
+
+        Vector3 forward = Vector3.Cross((B - A), (C - A));
+        Vector3 up = Vector3.up;
+
+        Vector3 crossForwardUp = Vector3.Cross(forward, up);
+        if (Mathf.Abs(crossForwardUp.magnitude) <= Mathf.Epsilon)
+        {
+            up = up + (C - c);
+        }
+
+        Rotation = Quaternion.LookRotation(forward, up);
     }
 
     public TriangleFact2() : base(){
-- 
GitLab