summaryrefslogtreecommitdiff
path: root/Thronefall_1_0/GameCode/SharpCornerMidigator.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-19 16:05:01 +0800
committerchai <215380520@qq.com>2024-05-19 16:05:01 +0800
commitc5f145786f4c6d2fe4bea831dfc16e52228920a5 (patch)
treea6ead7ea8266c767d58ed0f816dcd7a1dd75bd65 /Thronefall_1_0/GameCode/SharpCornerMidigator.cs
parent48b64e573a1709dc923cb9162b55be0246b3ff63 (diff)
* move
Diffstat (limited to 'Thronefall_1_0/GameCode/SharpCornerMidigator.cs')
-rw-r--r--Thronefall_1_0/GameCode/SharpCornerMidigator.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/Thronefall_1_0/GameCode/SharpCornerMidigator.cs b/Thronefall_1_0/GameCode/SharpCornerMidigator.cs
new file mode 100644
index 0000000..66500db
--- /dev/null
+++ b/Thronefall_1_0/GameCode/SharpCornerMidigator.cs
@@ -0,0 +1,46 @@
+using System.Collections.Generic;
+using Pathfinding;
+using UnityEngine;
+
+public class SharpCornerMidigator : MonoModifier
+{
+ public float extendCorners = 2f;
+
+ private List<Vector3> path;
+
+ private Vector3 pathPointLast;
+
+ private Vector2 toLastPoint;
+
+ private Vector2 toNextPoint;
+
+ private float angle;
+
+ private Vector2 normal2d;
+
+ private float strngth;
+
+ private Vector3 normal;
+
+ public override int Order => 100;
+
+ public override void Apply(Path _p)
+ {
+ if (_p.path != null && _p.path.Count != 0 && _p.vectorPath != null && _p.vectorPath.Count != 0)
+ {
+ path = _p.vectorPath;
+ pathPointLast = path[0];
+ for (int i = 1; i < path.Count - 1; i++)
+ {
+ toLastPoint = new Vector2(pathPointLast.x, pathPointLast.z) - new Vector2(path[i].x, path[i].z);
+ toNextPoint = new Vector2(path[i + 1].x, path[i + 1].z) - new Vector2(path[i].x, path[i].z);
+ angle = Vector2.Angle(toLastPoint, toNextPoint);
+ normal2d = -(toLastPoint.normalized + toNextPoint.normalized).normalized;
+ strngth = (180f - angle) / 180f;
+ normal = new Vector3(normal2d.x, 0f, normal2d.y);
+ pathPointLast = path[i];
+ path[i] += normal * strngth * extendCorners;
+ }
+ }
+ }
+}