Moved throttle adj to Instrument manager and made altimeter

This commit is contained in:
2026-02-18 12:19:50 +00:00
parent 5d353cf5fa
commit 344cb5009b
5 changed files with 141 additions and 77 deletions

View File

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

View File

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

View File

@@ -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<float>();
// 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;
}
}
}

View File

@@ -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()
{