using System.Collections; using System.Collections.Generic; 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; private const float MAX_GRAVITY = 9.8f; public float maxCoriolisForce; public float coriolisForceMultiplier = 2f; void Start() { rb = GetComponent(); rb.useGravity = false; } // Update is called once per frame void FixedUpdate() { 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 * Time.deltaTime, ForceMode.Acceleration); //rb.AddForce(direction * LerpGravity(), ForceMode.Acceleration); Debug.DrawRay(transform.position, coriolisVector * force, Color.red); } float LerpGravity() { return Mathf.Lerp(0, MAX_GRAVITY, Vector3.Distance(gameObject.transform.position, center.transform.position) / 12.75f); } float LerpCoriolisForce() { Debug.Log(Vector3.Distance(gameObject.transform.position, center.transform.position)); 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; } }