I am trying to add a different sound for the RCS thrusters (Rotation)
I have made a [SerializeField] value for the “SideThruster” and added the soundclip.
But I cannot get it to work the same as the main thruster sound.
If I use the !audioSource.isPlaying in the “Rotation” function the mainthruster sound stops working and if I hold thrust and rotate I can hear the different sounds sometimes, but not consistent.
What I want is that if you thrust up, and rotate, you hear the Main Thruster Sound, and the side thruster sound at the same time / layered.
I just cannot figure it out and its driving me nuts !
private void RespondtoThrustInput()
{
if (Input.GetKey(KeyCode.Space))
{
ApplyThrust();
}
else
{
audioSource.Stop(); // so audio only plays when you press space, stopping the audio on button release
}
}
private void ApplyThrust()
{
float thrustThisFrame = mainThrust * Time.deltaTime; // Time.deltaTime makes a calculation based off the last frame time which is a good indicater for the next frametime.
rigidBody.AddRelativeForce(Vector3.up * thrustThisFrame);
if (!audioSource.isPlaying) // ! means is not playing
{
audioSource.PlayOneShot(MainThruster);
}
}
private void RespondtoRotationInput()
{
float rotationThisFrame = rcsRotate * Time.deltaTime;
rigidBody.freezeRotation = true; // Take manual control of rotation -> prevent physics from spinning your rocket
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward * rotationThisFrame); // forward because unity uses left-handed coordination system
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(Vector3.back * rotationThisFrame);
}
rigidBody.freezeRotation = false; // Resume physics control.
}