Moved throttle adj to Instrument manager and made altimeter
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user