Browse Source

Added Coriolis script to objects

Added skybox to scene
develop
Joshua Reason 4 years ago
parent
commit
5f406647e2
3 changed files with 31 additions and 7 deletions
  1. BIN
      Assets/Scenes/Test Scenes/Static Ring.unity
  2. +27
    -4
      Assets/Scripts/Static Physics/CoriolisEffect.cs
  3. +2
    -1
      Assets/World Assets/Materials/DoubleSided.mat

BIN
Assets/Scenes/Test Scenes/Static Ring.unity (Stored with Git LFS) View File

size 316252

+ 27
- 4
Assets/Scripts/Static Physics/CoriolisEffect.cs View File

@ -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;
}
}

+ 2
- 1
Assets/World Assets/Materials/DoubleSided.mat View File

@ -8,7 +8,7 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: DoubleSided
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_Shader: {fileID: 4800000, guid: af3776ac6a322cb4da895ba92b2bc463, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
@ -75,3 +75,4 @@ Material:
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _NormalDefault: {r: 128, g: 128, b: 255, a: 1}

Loading…
Cancel
Save