summaryrefslogtreecommitdiffhomepage
path: root/Assets/Scripts/MovingSphere.cs
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-12-10 04:09:08 -0500
committerrealtradam <[email protected]>2022-12-10 04:09:08 -0500
commit1b7c9c7fc27541bb9420b91b3cd68f3a726e435c (patch)
tree461ccf5b4a933bfc5ba8c5d76f252034b4a39aec /Assets/Scripts/MovingSphere.cs
parentf4323d161a589b076b0ccd64e2a1cffcd09b0681 (diff)
downloadMagnet-Run-3D-1b7c9c7fc27541bb9420b91b3cd68f3a726e435c.tar.gz
Magnet-Run-3D-1b7c9c7fc27541bb9420b91b3cd68f3a726e435c.zip
orbiting camera
Diffstat (limited to 'Assets/Scripts/MovingSphere.cs')
-rw-r--r--Assets/Scripts/MovingSphere.cs28
1 files changed, 23 insertions, 5 deletions
diff --git a/Assets/Scripts/MovingSphere.cs b/Assets/Scripts/MovingSphere.cs
index dfbd378..77ac00f 100644
--- a/Assets/Scripts/MovingSphere.cs
+++ b/Assets/Scripts/MovingSphere.cs
@@ -4,6 +4,9 @@ using UnityEngine;
public class MovingSphere : MonoBehaviour
{
+ [SerializeField]
+ Transform playerInputSpace = default;
+
Rigidbody body;
Renderer renderer;
@@ -46,6 +49,8 @@ public class MovingSphere : MonoBehaviour
bool OnGround => groundContactCount > 0;
bool OnSteep => steepContactCount > 0;
+ Vector3 upAxis;
+
// 1.0 means walls
// 0.0 means floors
@@ -75,7 +80,19 @@ public class MovingSphere : MonoBehaviour
desiredJump |= Input.GetButtonDown("Jump");
- inputVelocity = new Vector3(playerInput.x, 0f, playerInput.y) * maxSpeed;
+ if(playerInputSpace)
+ {
+ Vector3 forward = playerInputSpace.forward;
+ forward.y = 0f;
+ forward.Normalize();
+ Vector3 right = playerInputSpace.right;
+ right.y = 0f;
+ right.Normalize();
+ inputVelocity =
+ ((forward * playerInput.y) + (right * playerInput.x)) * maxSpeed;
+ }
+ else
+ inputVelocity = new Vector3(playerInput.x, 0f, playerInput.y) * maxSpeed;
Color purple = Color.red + Color.blue;
//renderer.material.SetColor(
@@ -88,6 +105,7 @@ public class MovingSphere : MonoBehaviour
void FixedUpdate()
{
+ upAxis = -Physics.gravity.normalized;
UpdateState();
AdjustVelocity();
@@ -127,7 +145,7 @@ public class MovingSphere : MonoBehaviour
contactNormal.Normalize();
}
else
- contactNormal = Vector3.up;
+ contactNormal = upAxis;
}
void Jump()
@@ -152,8 +170,8 @@ public class MovingSphere : MonoBehaviour
stepsSinceLastJump = 0;
jumpPhase += 1;
- float jumpSpeed = Mathf.Sqrt(-2f * Physics.gravity.y * jumpHeight);
- jumpDirection = (jumpDirection + Vector3.up).normalized;
+ float jumpSpeed = Mathf.Sqrt(2f * Physics.gravity.magnitude * jumpHeight);
+ jumpDirection = (jumpDirection + upAxis).normalized;
float alignedSpeed = Vector3.Dot(velocity, jumpDirection);
if(alignedSpeed > 0f)
jumpSpeed = Mathf.Max(jumpSpeed - alignedSpeed, 0f);
@@ -169,7 +187,7 @@ public class MovingSphere : MonoBehaviour
return false;
if(!Physics.Raycast(
body.position,
- Vector3.down,
+ -upAxis,
out RaycastHit hit,
raycastProbeDistance,
probeMask