summaryrefslogtreecommitdiffhomepage
path: root/Assets/Scripts/CustomGravity.cs
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-12-11 02:54:14 -0500
committerrealtradam <[email protected]>2022-12-11 02:54:14 -0500
commit4e32bf914903b88a766e7d6166faf34cb4ba4620 (patch)
tree7479dc98bdd6c90433b3286b188d1e9b861bad78 /Assets/Scripts/CustomGravity.cs
parent1b7c9c7fc27541bb9420b91b3cd68f3a726e435c (diff)
downloadMagnet-Run-3D-4e32bf914903b88a766e7d6166faf34cb4ba4620.tar.gz
Magnet-Run-3D-4e32bf914903b88a766e7d6166faf34cb4ba4620.zip
single planet gravity
Diffstat (limited to 'Assets/Scripts/CustomGravity.cs')
-rw-r--r--Assets/Scripts/CustomGravity.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/Assets/Scripts/CustomGravity.cs b/Assets/Scripts/CustomGravity.cs
new file mode 100644
index 0000000..45f99bf
--- /dev/null
+++ b/Assets/Scripts/CustomGravity.cs
@@ -0,0 +1,23 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class CustomGravity : MonoBehaviour
+{
+
+ public static Vector3 GetGravity(Vector3 position, out Vector3 upAxis)
+ {
+ upAxis = GetUpAxis(position);
+ return position.normalized * Physics.gravity.y;
+ }
+ public static Vector3 GetGravity(Vector3 position)
+ {
+ return position.normalized * Physics.gravity.y;
+ }
+
+ public static Vector3 GetUpAxis(Vector3 position)
+ {
+ Vector3 up = position.normalized;
+ return Physics.gravity.y < 0f ? up : -up;
+ }
+}