diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index c31b376..16eca6c 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -768,8 +768,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 503400737} - - component: {fileID: 503400738} - - component: {fileID: 503400739} m_Layer: 0 m_Name: RocketRoot m_TagString: Untagged @@ -799,64 +797,6 @@ Transform: - {fileID: 986986471} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &503400738 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 503400736} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0b829ffad31babea7b993cfd70db13aa, type: 3} - m_Name: - m_EditorClassIdentifier: '::' - throttleAction: {fileID: -5533345291228272259, guid: c56ea0479fd0f296da411bf82c2c21a0, type: 3} - rampSpeed: 1 - mainEngine: {fileID: 1437557825} - throttleDisplay: {fileID: 348618513} ---- !u!114 &503400739 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 503400736} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3} - m_Name: - m_EditorClassIdentifier: Unity.InputSystem::UnityEngine.InputSystem.PlayerInput - m_Actions: {fileID: -944628639613478452, guid: c56ea0479fd0f296da411bf82c2c21a0, type: 3} - m_NotificationBehavior: 2 - m_UIInputModule: {fileID: 0} - m_DeviceLostEvent: - m_PersistentCalls: - m_Calls: [] - m_DeviceRegainedEvent: - m_PersistentCalls: - m_Calls: [] - m_ControlsChangedEvent: - m_PersistentCalls: - m_Calls: [] - m_ActionEvents: - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 701d83ea-56bd-4dbb-86c8-ba6b2fea3af1 - m_ActionName: 'Gameplay/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 6d7bcb28-89f8-4e38-97ad-fb542ddda1e6 - m_ActionName: 'Gameplay/Jump[/Keyboard/space]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: aeeb49bf-0c5f-47f6-b264-d0e1b3c04bad - m_ActionName: 'Gameplay/Throttle[/Keyboard/leftCtrl,/Keyboard/leftShift]' - m_NeverAutoSwitchControlSchemes: 0 - m_DefaultControlScheme: - m_DefaultActionMap: Gameplay - m_SplitScreenIndex: -1 - m_Camera: {fileID: 0} --- !u!1 &529781796 GameObject: m_ObjectHideFlags: 0 @@ -1295,6 +1235,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 467a162ba38457a3eaec2d8b2e313aee, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::Altimeter + rocketRigidbody: {fileID: 1172921199} + altitude: 500000 + gh: 9.8100004196167 + G: 0.00000000006674079868351224 + M: 5.972000204773125e+24 + RE: 6372000.217437744 --- !u!114 &894314917 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1317,6 +1263,7 @@ GameObject: m_Component: - component: {fileID: 986986471} - component: {fileID: 986986472} + - component: {fileID: 986986473} m_Layer: 0 m_Name: Cockpit m_TagString: Untagged @@ -1351,6 +1298,52 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2826e1784dd637a5e9b4fbdd6e93cb39, type: 3} m_Name: m_EditorClassIdentifier: '::' + throttleAction: {fileID: -5533345291228272259, guid: c56ea0479fd0f296da411bf82c2c21a0, type: 3} + rampSpeed: 1 + mainEngine: {fileID: 1437557825} + throttleDisplay: {fileID: 348618513} +--- !u!114 &986986473 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 986986470} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3} + m_Name: + m_EditorClassIdentifier: Unity.InputSystem::UnityEngine.InputSystem.PlayerInput + m_Actions: {fileID: -944628639613478452, guid: c56ea0479fd0f296da411bf82c2c21a0, type: 3} + m_NotificationBehavior: 2 + m_UIInputModule: {fileID: 0} + m_DeviceLostEvent: + m_PersistentCalls: + m_Calls: [] + m_DeviceRegainedEvent: + m_PersistentCalls: + m_Calls: [] + m_ControlsChangedEvent: + m_PersistentCalls: + m_Calls: [] + m_ActionEvents: + - m_PersistentCalls: + m_Calls: [] + m_ActionId: 701d83ea-56bd-4dbb-86c8-ba6b2fea3af1 + m_ActionName: 'Gameplay/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]' + - m_PersistentCalls: + m_Calls: [] + m_ActionId: 6d7bcb28-89f8-4e38-97ad-fb542ddda1e6 + m_ActionName: 'Gameplay/Jump[/Keyboard/space]' + - m_PersistentCalls: + m_Calls: [] + m_ActionId: aeeb49bf-0c5f-47f6-b264-d0e1b3c04bad + m_ActionName: 'Gameplay/Throttle[/Keyboard/leftCtrl,/Keyboard/leftShift]' + m_NeverAutoSwitchControlSchemes: 0 + m_DefaultControlScheme: + m_DefaultActionMap: Gameplay + m_SplitScreenIndex: -1 + m_Camera: {fileID: 0} --- !u!1 &989507022 GameObject: m_ObjectHideFlags: 0 @@ -1499,6 +1492,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 219e9801db9b4c278907929162e4507c, type: 3} m_Name: m_EditorClassIdentifier: '::' + mainEngine: {fileID: 1437557825} --- !u!54 &1172921199 Rigidbody: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Altimeter.cs b/Assets/Scripts/Altimeter.cs index e5fd9d5..b285d59 100644 --- a/Assets/Scripts/Altimeter.cs +++ b/Assets/Scripts/Altimeter.cs @@ -1,7 +1,27 @@ +using Unity.VisualScripting; using UnityEngine; public class Altimeter : MonoBehaviour { - void Start() { } - void Update() { } + [Header("References")] + public Rigidbody rocketRigidbody; // Reference to the rocket's Rigidbody + [Header("Data")] + public double altitude = 0; // Current altitude + public double gh = 9.81f; // Gravitational acceleration + + [Header("Settings")] + [SerializeField] private double G = 6.67408f * Mathf.Pow(10, -11); // Gravitational constant + [SerializeField] private double M = 5.972f * Mathf.Pow(10, 24); // Mass of Earth + [SerializeField] private double RE = 6.372f * Mathf.Pow(10, 6); // Radius of Earth + private double GM; // Gravitational parameter (G * M) + + void Start() + { + GM = G * M; // Calculate the gravitational parameter + } + void Update() + { + altitude = rocketRigidbody.position.y; // Update altitude based on the rocket's vertical position + gh = (double)(GM / Mathf.Pow((float)(RE + altitude), 2)); // Calculate gravitational acceleration at current altitude + } } diff --git a/Assets/Scripts/InstrumentManager.cs b/Assets/Scripts/InstrumentManager.cs index e717627..208b41e 100644 --- a/Assets/Scripts/InstrumentManager.cs +++ b/Assets/Scripts/InstrumentManager.cs @@ -1,16 +1,63 @@ using UnityEngine; +using UnityEngine.InputSystem; +using UnityEngine.UI; public class InstrumentManager : MonoBehaviour { - // Start is called once before the first execution of Update after the MonoBehaviour is created - void Start() + [Header("Input")] + public InputActionReference throttleAction; // Your Input Action reference + + [Header("Throttle Settings")] + public float rampSpeed = 1f; // Units per second + + [Header("References")] + public MainEngine mainEngine; // Reference to your engine script + // Referance to TextMeshPro Throttle slider + public Slider throttleDisplay; // Reference to UI Slider component + + void OnEnable() { - + if (throttleAction != null) + { + throttleAction.action.Enable(); + Debug.Log("Throttle action enabled."); + } + else + { + Debug.LogWarning("Throttle action reference is not set!"); + } + } + + void OnDisable() + { + if (throttleAction != null) + throttleAction.action.Disable(); } - // Update is called once per frame void Update() { + if (throttleAction == null || mainEngine == null) + return; + + // Read input (-1, 0, +1) + float input = throttleAction.action.ReadValue(); + // Debug what the input is reading + //Debug.Log($"Input value: {input}"); + + // Calculate new throttle target + float target = mainEngine.throttleInput + input * rampSpeed * Time.deltaTime; + + // Clamp between 0 and 1 + mainEngine.throttleInput = Mathf.Clamp01(target); + + // Debug the throttle value + //Debug.Log($"Throttle value: {mainEngine.throttleInput}"); + + // Update the throttle display + if (throttleDisplay != null) + { + throttleDisplay.value = mainEngine.throttleInput; + } } } diff --git a/Assets/Scripts/RocketPhysics.cs b/Assets/Scripts/RocketPhysics.cs index e1692e1..0f843d0 100644 --- a/Assets/Scripts/RocketPhysics.cs +++ b/Assets/Scripts/RocketPhysics.cs @@ -2,6 +2,10 @@ using UnityEngine; public class RocketPhysics : MonoBehaviour { + [Header("References")] + public MainEngine mainEngine; + + // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { diff --git a/UserSettings/Layouts/default-6000.dwlt b/UserSettings/Layouts/default-6000.dwlt index 1e4b8dd..d2ab434 100644 --- a/UserSettings/Layouts/default-6000.dwlt +++ b/UserSettings/Layouts/default-6000.dwlt @@ -301,7 +301,7 @@ MonoBehaviour: m_Pos: serializedVersion: 2 x: 0 - y: 87 + y: 0 width: 1920 height: 36 m_SerializedDataModeController: @@ -618,7 +618,7 @@ MonoBehaviour: m_Data: 46266 m_ExpandedIDs: - m_Data: 0 - - m_Data: 46050 + - m_Data: 46044 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -651,7 +651,7 @@ MonoBehaviour: m_Data: 0 m_ExpandedIDs: - m_Data: 0 - - m_Data: 46050 + - m_Data: 46044 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -733,8 +733,8 @@ MonoBehaviour: m_TextWithWhitespace: "Inspector\u200B" m_Pos: serializedVersion: 2 - x: 1466 - y: 123 + x: 1467 + y: 24 width: 453 height: 911 m_SerializedDataModeController: @@ -785,7 +785,7 @@ MonoBehaviour: m_Pos: serializedVersion: 2 x: 0 - y: 123 + y: 24 width: 362 height: 528 m_SerializedDataModeController: @@ -804,8 +804,7 @@ MonoBehaviour: m_SceneHierarchy: m_TreeViewState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: - - m_Data: 45246 + m_SelectedIDs: [] m_LastClickedID: m_Data: 0 m_ExpandedIDs: @@ -1371,8 +1370,8 @@ MonoBehaviour: m_TextWithWhitespace: "Game\u200B" m_Pos: serializedVersion: 2 - x: 363 - y: 123 + x: 364 + y: 24 width: 1101 height: 528 m_SerializedDataModeController: @@ -1475,7 +1474,7 @@ MonoBehaviour: m_Pos: serializedVersion: 2 x: 0 - y: 677 + y: 578 width: 1465 height: 357 m_SerializedDataModeController: