|
|
@ -4,6 +4,9 @@ using UnityEngine; |
|
|
|
|
|
|
|
public class CoriolisEffect : MonoBehaviour |
|
|
|
{ |
|
|
|
|
|
|
|
public Vector3 downDir => Vector3.ProjectOnPlane((transform.position - center.transform.position), Vector3.forward); |
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
public GameObject center; |
|
|
|
private Rigidbody rb; |
|
|
@ -13,16 +16,22 @@ public class CoriolisEffect : MonoBehaviour |
|
|
|
void Start() |
|
|
|
{ |
|
|
|
rb = GetComponent<Rigidbody>(); |
|
|
|
rb.useGravity = false; |
|
|
|
} |
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void FixedUpdate() |
|
|
|
{ |
|
|
|
Vector3 direction = (transform.position - center.transform.position).normalized; |
|
|
|
Vector3 coriolisVector = Vector3.Cross(direction, new Vector3(0,0,1)).normalized; |
|
|
|
if (IsGrounded()) |
|
|
|
return; |
|
|
|
|
|
|
|
Vector3 direction = downDir.normalized; |
|
|
|
Vector3 coriolisVector = -Vector3.Cross(direction, new Vector3(0,0,1)).normalized; |
|
|
|
Debug.Log(LerpCoriolisForce()); |
|
|
|
float force = LerpCoriolisForce(); |
|
|
|
rb.AddForce(coriolisVector * force * coriolisForceMultiplier, ForceMode.Acceleration); |
|
|
|
|
|
|
|
rb.AddForce(coriolisVector * force * coriolisForceMultiplier * Time.deltaTime, ForceMode.Acceleration); |
|
|
|
//rb.AddForce(direction * LerpGravity(), ForceMode.Acceleration);
|
|
|
|
Debug.DrawRay(transform.position, coriolisVector * force, Color.red); |
|
|
|
} |
|
|
|
|
|
|
@ -34,6 +43,20 @@ public class CoriolisEffect : MonoBehaviour |
|
|
|
float LerpCoriolisForce() |
|
|
|
{ |
|
|
|
Debug.Log(Vector3.Distance(gameObject.transform.position, center.transform.position)); |
|
|
|
return Mathf.Lerp(maxCoriolisForce, 0, Vector3.Distance(gameObject.transform.position, center.transform.position) / 12.75f); |
|
|
|
return Mathf.Lerp(maxCoriolisForce, 0, downDir.magnitude / 12.75f); |
|
|
|
} |
|
|
|
|
|
|
|
private bool IsGrounded() |
|
|
|
{ |
|
|
|
|
|
|
|
Ray ray = new Ray(transform.position, downDir.normalized); |
|
|
|
RaycastHit hit; |
|
|
|
|
|
|
|
if (Physics.Raycast(ray, out hit, 0.25f)) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |