Jump to content

AudioSource silent in space


Recommended Posts

Hi I added some sound effects to my IVA. Therefore I'm adding an AudioSource to a part.

alarmAs = light.AddComponent<AudioSource>();
AudioClip clip = GameDatabase.Instance.GetAudioClip(alarmSound);
alarmAs.clip = clip;
alarmAs.dopplerLevel = DOPPLER_LEVEL;
alarmAs.rolloffMode = AudioRolloffMode.Linear;
alarmAs.Stop();
alarmAs.loop = true;
alarmAs.minDistance = MIN_DIST;
alarmAs.maxDistance = MAX_DIST;
alarmAs.volume = 1f;

if (!alarmAs.isPlaying)
{
alarmAs.Play();
}

When I test it on the launch pad everything works well, but when i hyperedit my test craft into orbit I can't hear the sound effects. I can't find the reason for this. Can anybody explain this behavior?

Link to comment
Share on other sites

maybe your sound stays at the launchpad..

in terms of:

the parent value of the audio-gameobject is not set correctly..

so if the ship moves, the audio stays at the global location it is created..

alarmAs.transform.parent = ???

or

light.transform.parent = ???

hth

Link to comment
Share on other sites

the light is a part of the iva 3d-model and the parent is set to parent in the model. As I understand it component do not have their own transform. so if the model moves so should the audio source. Or did I miss something.

I did some testing, when I add the Audiosource component to the internalModel the audiosource stays where it was added, when I add the component to the part itself it moves with the craft. It behaves like the iva would stay in one place even if the craft is moving. Can somebody explain this? For the time I'll add the audio to the part.

Edited by N3h3mia
Link to comment
Share on other sites

I juts saw, you are swiss - so am I lol..

(Vo wo bisch denn? Mich findsch z'Laufe BL..)

>As I understand it component do not have their own transform.

This is wrong and right..

components do not have an own but they are added to a game object - and this game object has a transform..

>Can somebody explain this? For the time I'll add the audio to the part.

I can't.. sorry..

I don't know if that is "normal" but I doubt it..

never seen this - so it might be something wrong in your set up..

Link to comment
Share on other sites

>(Vo wo bisch denn? Mich findsch z'Laufe BL..)

Stadel Züri Unterland

>This is wrong and right..

>components do not have an own but they are added to a game object - and this game object has a transform..

That's what I meant. The light has a mesh component, so if it would stay in a place so should the mesh but only the AudioSource doesn't move.

>I don't know if that is "normal" but I doubt it.

I doubt it too, but IVA's to behave strange sometimes, at least for me they do.

Link to comment
Share on other sites

There is a bug with the IVA light sources. If you move a craft with an IVA away from its starting point, you can see that the IVA light remains there, lighting up the ground. You appear to be attaching your sound to this bugged light. You can test this with your sound by driving a rover away from the start point and seeing if the sound stays with it. Parent the sound to the IVA part's GameObject to have the effect you're looking for.

Link to comment
Share on other sites

There is a bug with the IVA light sources. If you move a craft with an IVA away from its starting point, you can see that the IVA light remains there, lighting up the ground. You appear to be attaching your sound to this bugged light. You can test this with your sound by driving a rover away from the start point and seeing if the sound stays with it. Parent the sound to the IVA part's GameObject to have the effect you're looking for.

I did some testing with a rover and can confirm that the sound stays in it's starting point. But it is not limited to lights. I have the same problem with an other IVA there I attach the AudioSource to a GameObject that is not a light. It is the GameObject holding the model for this part in the IVA.

eKGwv4H.png

Here is the method used to add the AudioSource. maybe somebody can point out my error. It is part of a class that is an InternalModule not a PartModule.

private void initPartObjects()
{
if (part.internalModel != null)
{
GameObject labIVA = part.internalModel.gameObject.transform.GetChild(0).GetChild(0).gameObject;
if (labIVA.GetComponent<MeshFilter>().name == "Lab1IVA")
{
GameObject ffr = labIVA.transform.GetChild(2).gameObject;
pump1 = ffr.transform.GetChild(1);
pump2 = ffr.transform.GetChild(2);

//pumpAs = ffr.AddComponent<AudioSource>(); //Does not work
pumpAs = part.gameObject.AddComponent<AudioSource>(); //Workaround: using GameObjects from the internal model does not work AS would stay in the place it was added.

AudioClip clip = GameDatabase.Instance.GetAudioClip(pumpSound);
pumpAs.clip = clip;
pumpAs.dopplerLevel = DOPPLER_LEVEL;
pumpAs.rolloffMode = AudioRolloffMode.Logarithmic;
pumpAs.Stop();
pumpAs.loop = true;
pumpAs.minDistance = MIN_DIST;
pumpAs.maxDistance = MAX_DIST;
pumpAs.volume = 1f;
}
}
}

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...