Browse Source

Started work on static ship physics

-Created Test Scene
-Implemented basic artificial gravity script
develop
Joshua Reason 4 years ago
parent
commit
ae625462b9
7 changed files with 106 additions and 0 deletions
  1. +8
    -0
      Assets/Scenes/Test Scenes.meta
  2. BIN
      Assets/Scenes/Test Scenes/Static Ring.unity
  3. +7
    -0
      Assets/Scenes/Test Scenes/Static Ring.unity.meta
  4. +43
    -0
      Assets/Scripts/Static Physics/ArtificialGravity.cs
  5. +11
    -0
      Assets/Scripts/Static Physics/ArtificialGravity.cs.meta
  6. +23
    -0
      Assets/Scripts/Static Physics/RotationController.cs
  7. +11
    -0
      Assets/Scripts/Static Physics/RotationController.cs.meta

+ 8
- 0
Assets/Scenes/Test Scenes.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 077abae28faa3204f8b0fec20e7e7522
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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

size 202288

+ 7
- 0
Assets/Scenes/Test Scenes/Static Ring.unity.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ebec2921b133db44b985b8127c0ab010
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 43
- 0
Assets/Scripts/Static Physics/ArtificialGravity.cs View File

@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class ArtificialGravity : MonoBehaviour
{
[SerializeField]
private RotationController Ship;
private Rigidbody rb;
private void OnEnable()
{
rb = GetComponent<Rigidbody>();
rb.useGravity = false;
if (Ship == null)
Ship = FindObjectOfType<RotationController>();
}
private void FixedUpdate()
{
ApplyGravity();
}
private void ApplyGravity()
{
if (Ship.RotationPeriod <= 0)
return;
Vector3 direction = (transform.position - Ship.Position);
float force = direction.magnitude * Mathf.Pow(2 * Mathf.PI / Ship.RotationPeriod, 2);
rb.AddForce(direction.normalized * force * Time.fixedDeltaTime, ForceMode.Acceleration);
}
}

+ 11
- 0
Assets/Scripts/Static Physics/ArtificialGravity.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a67b59dce8f5cd24b926f5f79c0b67ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 23
- 0
Assets/Scripts/Static Physics/RotationController.cs View File

@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotationController : MonoBehaviour
{
#region Read-Only Fields
public float RotationPeriod => m_RotationPeriod;
public Vector3 Position => transform.position;
#endregion Read-Only Fields
[SerializeField]
private float m_RotationPeriod;
private void FixedUpdate()
{
transform.Rotate(Vector3.forward, 360/m_RotationPeriod * Time.fixedDeltaTime, Space.World);
}
}

+ 11
- 0
Assets/Scripts/Static Physics/RotationController.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c4b2eee9c899c2a458f8516e0666c57d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save