using UnityEngine; using Player.Movement; using Player.Information; namespace Player.Interactions { public class JetPack : MonoBehaviour { // in Newtons [SerializeField] private float thrustStrength; // in seconds [SerializeField] private float maxLoftTime; // in seconds per seconds [SerializeField] private float loftReclaimRate; [SerializeField] private float airLoftReclaimRate; // particle system for jetpack [SerializeField] private ParticleSystem flames; private bool active; private float loftTime; private PlayerPhysics playerPhysics; private PlayerStats playerStats; private void Start() { SetActiveThrust(false); loftTime = maxLoftTime; playerPhysics = gameObject.GetComponent(); playerStats = gameObject.GetComponent(); } private void Update() { if (playerStats.jetpackEnabled) { if (Input.GetKey(KeyCode.Q) ) { if (loftTime > 0f) { SetActiveThrust(true); loftTime = Mathf.Max(0f, loftTime - Time.deltaTime); } else { SetActiveThrust(false); } } else { SetActiveThrust(false); if (loftTime < maxLoftTime) { if (playerPhysics.isGrounded()) loftTime = Mathf.Min(maxLoftTime, loftTime + loftReclaimRate * Time.deltaTime); else loftTime = Mathf.Min(maxLoftTime, loftTime + airLoftReclaimRate * Time.deltaTime); } } playerStats.SetThrust(loftTime / maxLoftTime); } } public Vector3 ThrustForce() { if (active) return new Vector3(0f, thrustStrength, 0f); return Vector3.zero; } private void SetActiveThrust(bool state) { active = state; SetEmission(state); } private void SetEmission(bool state) { var emission = flames.emission; emission.enabled = state; } public void ResetThrust() { loftTime = maxLoftTime; } } }