-Created Test Scene -Implemented basic artificial gravity scriptdevelop
@ -0,0 +1,8 @@ | |||||
fileFormatVersion: 2 | |||||
guid: 077abae28faa3204f8b0fec20e7e7522 | |||||
folderAsset: yes | |||||
DefaultImporter: | |||||
externalObjects: {} | |||||
userData: | |||||
assetBundleName: | |||||
assetBundleVariant: |
size 202288 |
@ -0,0 +1,7 @@ | |||||
fileFormatVersion: 2 | |||||
guid: ebec2921b133db44b985b8127c0ab010 | |||||
DefaultImporter: | |||||
externalObjects: {} | |||||
userData: | |||||
assetBundleName: | |||||
assetBundleVariant: |
@ -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); | |||||
} | |||||
} |
@ -0,0 +1,11 @@ | |||||
fileFormatVersion: 2 | |||||
guid: a67b59dce8f5cd24b926f5f79c0b67ec | |||||
MonoImporter: | |||||
externalObjects: {} | |||||
serializedVersion: 2 | |||||
defaultReferences: [] | |||||
executionOrder: 0 | |||||
icon: {instanceID: 0} | |||||
userData: | |||||
assetBundleName: | |||||
assetBundleVariant: |
@ -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); | |||||
} | |||||
} |
@ -0,0 +1,11 @@ | |||||
fileFormatVersion: 2 | |||||
guid: c4b2eee9c899c2a458f8516e0666c57d | |||||
MonoImporter: | |||||
externalObjects: {} | |||||
serializedVersion: 2 | |||||
defaultReferences: [] | |||||
executionOrder: 0 | |||||
icon: {instanceID: 0} | |||||
userData: | |||||
assetBundleName: | |||||
assetBundleVariant: |