nexal
Full vMember
Posts: 57
|
Post by nexal on Jul 8, 2019 9:13:36 GMT
Hi guys I was wondering if it is possible to connect an audio file to the AI enemy character detection system so that in addition to going to the player, can talk or scream etc. Thank's
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jul 9, 2019 14:04:39 GMT
no one who knows if it can be done?
|
|
|
Post by magique on Jul 9, 2019 20:14:32 GMT
I will be doing this same thing, but I haven't looked at how to do it yet. If I find out one way or the other I'll post here and let you know.
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jul 9, 2019 20:38:37 GMT
Thanks Magique. It is also true that I can insert a trigger that plays the sound but I think it was nicer when the AI character detects the player.
|
|
|
Post by magique on Jul 10, 2019 15:06:17 GMT
Thanks Magique. It is also true that I can insert a trigger that plays the sound but I think it was nicer when the AI character detects the player. OK, so I created a custom state script to play sounds in order to get this to work. I'm using MasterAudio so if you use this script and don't use MasterAudio, you'll have to modify the script to play from a regular audio source. namespace Invector.vCharacterController.AI.FSMBehaviour
{
using DarkTonic.MasterAudio;
public class vAIPlaySound : vStateAction
{
public override string defaultName
{
get
{
return "Play Sound";
}
}
public string soundName;
public float volume = 1f;
public override void DoAction(vIFSMBehaviourController fsmBehaviour, vFSMComponentExecutionType executionType = vFSMComponentExecutionType.OnStateUpdate)
{
PlaySound(fsmBehaviour);
}
protected virtual void PlaySound(vIFSMBehaviourController fsmBehaviour)
{
if (fsmBehaviour != null)
{
MasterAudio.PlaySound3DAtTransform(soundName, fsmBehaviour.aiController.transform, volume);
}
}
}
}
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jul 11, 2019 7:55:06 GMT
Thanks Magique for the script I replaced masteraudio with audiosource but the script makes me 6 errors. I imagine the script should be applied to the AI character but unfortunately I'm not good with scripts so I can only modify them but not resolve errors.
|
|
|
Post by magique on Jul 11, 2019 13:52:37 GMT
Thanks Magique for the script I replaced masteraudio with audiosource but the script makes me 6 errors. I imagine the script should be applied to the AI character but unfortunately I'm not good with scripts so I can only modify them but not resolve errors. The state has to be added to your FSM. Here is where I put mine for testing purposes. See image. It has been added as the Shout state. As for your errors, are they compile errors? I would need to see the script to figure out what's wrong there.
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jul 11, 2019 16:38:29 GMT
Thanks Magique for the script I replaced masteraudio with audiosource but the script makes me 6 errors. I imagine the script should be applied to the AI character but unfortunately I'm not good with scripts so I can only modify them but not resolve errors. The state has to be added to your FSM. Here is where I put mine for testing purposes. See image. It has been added as the Shout state. As for your errors, are they compile errors? I would need to see the script to figure out what's wrong there. Maybe I understood the problem. My AI character is an NPC and not an AI template. My idea if possible is to add the audio file to the v_AIController script. In your opinion, it's too complicated to do it?
|
|
|
Post by magique on Jul 11, 2019 17:10:04 GMT
This is a support forum for FSM AI Template so I assumed you were using that. I don't really see how you are going to know when to play your audio file if you are just attaching a script to an object with vAIController. I don't think I would take that approach, especially if you are not that knowledgeable about scripting.
|
|
nexal
Full vMember
Posts: 57
|
Post by nexal on Jul 12, 2019 10:19:43 GMT
Sorry I got the wrong section. I think you are right, if it is too complicated to modify the vAIController script to insert the audio file, considering that I don't understand much about scripts I have to let it go. Thank you for trying to help me Magique.
|
|
azul
Junior vMember
Posts: 38
|
Post by azul on Jul 16, 2019 4:07:46 GMT
Thanks for the script, magique! I am also interested in getting this to work using unity's audio. Can anyone point us in the right direction? As far as triggering the audioclip, wouldn't that be called via the AI_PlaySound under Shout>AnyState?
|
|
|
Post by magique on Jul 16, 2019 13:47:53 GMT
Thanks for the script, magique! I am also interested in getting this to work using unity's audio. Can anyone point us in the right direction? As far as triggering the audioclip, wouldn't that be called via the AI_PlaySound under Shout>AnyState? For regular audio clip, you should modify my script to something like this: namespace Invector.vCharacterController.AI.FSMBehaviour
{
public class vAIPlaySound : vStateAction
{
public override string defaultName
{
get
{
return "Play Sound";
}
}
public AudioClip audioClip;
public float volume = 1f;
public override void DoAction(vIFSMBehaviourController fsmBehaviour, vFSMComponentExecutionType executionType = vFSMComponentExecutionType.OnStateUpdate)
{
PlaySound(fsmBehaviour);
}
protected virtual void PlaySound(vIFSMBehaviourController fsmBehaviour)
{
if (fsmBehaviour != null)
{ GetComponent<AudioSource>(). clip = audioClip;
GetComponent<AudioSource>().volume = volume; GetComponent<AudioSource>().Play();
}
}
}
} Note that I haven't tested this. Also, you must have an AudioSource on your game object. And, the 3 calls made to GetComponent<AudioSource> could be cached or a reference made to it.
|
|