Search Unity

[RELEASED] Emerald AI 3.2 (New Sound Detection) - The Ultimate Universal AAA Quality AI Solution

Discussion in 'Assets and Asset Store' started by BHS, Jun 26, 2015.

  1. hsxtreme

    hsxtreme

    Joined:
    Apr 14, 2017
    Posts:
    55
  2. The_Uber_Rasta

    The_Uber_Rasta

    Joined:
    Feb 25, 2014
    Posts:
    8
    hsxtreme and TheSeawolf like this.
  3. TheSeawolf

    TheSeawolf

    Joined:
    Apr 10, 2015
    Posts:
    267
    Emerald Ai and Unistorm integration with Ultimate Survival will be great.

    @BHS , I'm using emerald, unistorm and crux with ultimate survival. Have you been in contact with @Winterbyte312 to discuss this integration as it seems quite a few of us use your products and ultimate survival.
     
    hsxtreme and The_Uber_Rasta like this.
  4. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Hey Matt,

    Not currently, but that is a little specific. Multiple hit animations will be added with the 1.4 update. You could possibly have a custom script handle this once 1.4 is released.


    Hey guys,

    Support for Ultimate Survival is definitely something that will be added on our end as well. It's great to see the developers of Ultimate Survival will also be adding support for Emerald.
     
    Last edited: May 23, 2017
    hsxtreme likes this.
  5. hsxtreme

    hsxtreme

    Joined:
    Apr 14, 2017
    Posts:
    55

    Thank you for your support
     
  6. Will-D-Ramsey

    Will-D-Ramsey

    Joined:
    Dec 9, 2012
    Posts:
    221
    Anybody know of any forums for implementing Emerald with Ultimate Survival?
     
  7. Sliceandkill

    Sliceandkill

    Joined:
    Dec 2, 2014
    Posts:
    89
    If I remember correctly, I once read that Emerald has some kind of culling. It's still true or ever was? :)
     
  8. lukamas233

    lukamas233

    Joined:
    Jan 6, 2015
    Posts:
    29
    Hi, I have a question, so Is it possible for Collision off the nav-mesh for the AI,

    When I add a box collider to an object in the scene, it walks through it, how can I fix this.
     
  9. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Hey there!

    Yes, you would just use a LOD Group. Details on setting it up can be found here: https://docs.unity3d.com/Manual/class-LODGroup.html

    Once you AI's Skinned Mesh Renderer becomes culled, it Emerald will disable it until it becomes unculled.


    Hey there!

    You would use a NavMesh Obstacle. Details on this can be found here: https://docs.unity3d.com/Manual/class-NavMeshObstacle.html
     
  10. lod3

    lod3

    Joined:
    Mar 21, 2012
    Posts:
    679
    Any update on this?
     
    Teila likes this.
  11. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Hi,
    Does it includes pooling system and culling like Ice Creatures has ?
    These are very important features any AI system should have out of the box.
     
  12. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Hey there!

    Yes, the 1.4 version is still being worked on. It's taking a little longer than expected due to the amount of work that's being done. A lot of the system is being rewritten which will make future updates a lot quicker. We will be sure to post a status update with everything that's being done sometime this week.


    Hey there!

    Emerald has a built-in culling feature using Unity's LOD Group component. When applied, Emerald automatically disables the AI to help with performance. Information on setting up can be found here: https://docs.unity3d.com/Manual/class-LODGroup.html

    As for object pooling, Emerald does not include an object pooling system. However, there are a few really good free object pooling systems that can be found online that do a great job.
     
  13. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    It will increase the price of the solution and one complete plugin is always better than dealing with many.
    I ask because Ice Creatures do AI and has pooling/unpooling around some home location included, and it's not so hard to code feature.
     
  14. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    I totally agree. An object pooling system is certainly something we can add in the near feature. I'll see if it can be squeezed into the 1.4 update. It's worth noting that the 1.4 update will bring support for object pooling allowing AI to reset when being set to inactive.
     
    Last edited: Jun 16, 2017
    julianr and zenGarden like this.
  15. Gunsrequiem

    Gunsrequiem

    Joined:
    May 17, 2017
    Posts:
    71
    Are you still planning to implement other pathfinding options, or have you already? I ask because the Unity NavMesh creates a lot of FPS issues when using the Crux spawner and Emerald AI game objects.
     
  16. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    We are currently looking into pathfinding options for Emerald. However, Unity's been reworking its NavMesh, and the ability to use it dynamically, so it may end up being a viable pathfinding option.

    As for Crux, version 1.1 will bring improved performance, the ability to spawn to nodes that keeps AI inactive until a player is within the customizable range, object pooling, and tons more. All this will help improve performance quite a bit, especially the ability to keep spawned AI inactive when not in range. So, even if you are using Unity's NavMesh, you shouldn't see it affecting performance with the new update.

    The Crux update should be ready within the next few weeks. Most of Emerald is being rewritten, and is a little more time consuming, so there's no exact release date for it. However, both assets are currently being worked on.
     
  17. Gunsrequiem

    Gunsrequiem

    Joined:
    May 17, 2017
    Posts:
    71
    Those sound like some very welcome changes, and I'm even more excited to get it fully implemented with my project. I managed to reduce the FPS lag quite a bit by manually baking the terrain without relying on Unity's beta NavMesh components, at least for now. Down the road, once I'm preparing for the demo launch, I'll make the decision on how I'm going to implement pathfinding for the long haul. So far, Emerald AI and Crux have been great!
     
    BHS likes this.
  18. GenPhi

    GenPhi

    Joined:
    Dec 27, 2014
    Posts:
    12
    Can't wait to see the update. From what it sounds like it should be a version release; Emerald AI 2.0!. :) Let us know if you need beta testers. I'm sure there are a few of us that would love to help. ;)
    Question: Will this be a overwrite of the version we have now or a complete replacement? Will we have to rebuild the AI on our enemies and the like?
     
  19. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Yes, it will be quite the update.

    We will be looking for some beta testers when we are closer to release. I'll be sure to post it where when we are ready.

    All AI from previous versions of Emerald should work perfectly fine with the new version of Emerald.
     
    GenPhi likes this.
  20. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    I use UFPS and Emerald AI to create a game. I follow the tutorial of how to integrate both systems.
    I was able to receive and deal damage the the AI, but I don't know how to setup animations on the AI.
    I get an error that the Emerald AI Agent has no animation Component attached to it, if I'm not wrong, the animation Component use Legacy animations. I want to use Mecanim animations, to be able to use mecanim animations is necessary to use Animator Component. How I can use the animator component with Emerald AI?
     
    Last edited: Jun 29, 2017
  21. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    How is performance compared to previous version? I had to abandon Emerald AI because it was very sluggish with more than a few AI in the scene. I'd be interested in beta testing new version if it promises major performance improvements.
     
  22. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Hey there!

    Ensure that your AI has an Animator Component and an Avatar assigned to the Avatar slot of your Animator Component. An Animator Controller will be generated for you with Emerald.


    Hey there!

    It will be improved quite a bit. However, the current version is not sluggish, at least from what I've tested. Of course it could use some improvements, but that doesn't mean it is usable. It's certainly usable with more than a few AI. What are you computer specs and what performance issues have you been experiencing? I'd be more than happy to take a look at them to see if there's something that isn't happening on my end.
     
  23. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    At the time I was using Emerald AI, my computer specs were different than they are now. But I was also testing results on the Wii U. So just think in terms of Wii U power. Although I've moved my project to the PC now, performance is still a concern. From what I remember, there was a lot of room for improvement in the code for more modular systems. It often did a lot of work in areas that a particular AI might not even need. But it's been a while so I can't be more specific. But, yeah, I'd like to try the beta if possible. Will it work with Unity 5.6.2f1?
     
  24. txarly

    txarly

    Joined:
    Apr 27, 2016
    Posts:
    197
    Hi,

    I think field of view and sound detection are a very important part of an AI asset.Are they going to be integrated any time soon?

    thanks, and keep the good work
     
  25. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    The 1.3.5 update made some improvements and optimizations to the code. The 1.4 update will do the same, but many portions of the code will be rewritten, simplified, and more efficient. You can certainly be a beta tester when the beta is ready. Emerald should work with Unity 5.6.2f1.


    Hey there!

    We are going to try and fit these features into the 1.4 update, but if they don't make it in, they will be added shortly after.
     
    magique and julianr like this.
  26. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    hey i read much about the 1.4 update i really want to buy this asset but not before the update Comes out so the question you have a release date ?
     
    GenPhi likes this.
  27. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    I create a game using UFPS and Emerald AI, but the enemies that use Emerald AI didn't respect BoxColliders on walls, they get through walls, to resolve that I use Nav Mesh Obstacles, but sometimes they get stuck on these NavMesh Obstacles, how can I avoid that?

    I have another problem, Emerald AI agents have a area that they are able to wander, but sometimes they reach a NavMesh Obstacle and continue to wander in wall direction. There's something that I can do to avoid that?
     
  28. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    It doesn't currently have a release date. There's a lot that needs to be done so there's no way to predict exactly how long it will take. But I can assure you it will be well worth the wait.


    Hey there!

    It sounds like you need to rebake your NavMesh. Any time you add new static objects to your scene, you need to rebake the NavMesh. If an AI is going through any mesh, it doesn't have proper NavMesh. Ensure that your objects are marked as Static so the NavMesh can include it in the NavMesh baking.

    If an AI is getting stuck on a NavMesh Obstacle, increase its Obstacle Avoidance Quality and Radius. This setting can be found on the AI's NavMesh Agent component.
     
    Salja likes this.
  29. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Good Morning,
    It's quite a bit I am using Emerald (super good and easy) but I still could not solve a small and annoying issue.
    I wrote it before and here is my Problem :
    I set the animal AI by using Mecanim and, even if the rotation speed is very low (0.5) the AI rotate quite fast and innatural. Is there no way to make it rotate and orient towards the next Waypoint in a smoother way?
    Thanks in advance,

    Dom
     
    Last edited: Jul 12, 2017
  30. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    @BHS
    Hi, I'm interested in Emerald AI and got some questions before I buy:
    1. How flexible can we adjust the creature's actions? Can I set my own action logic for an AI, for example, wolves attacks in packs will have some of them detour around to your back and attack. Lone wolf will only attack directly or runaway.
    Deers in packs will only focus on there leader's commands, stags will attack when something invades, hinds will protect cubs while they are fleeing.
    Is there a behavior designer-like function for us to add our own behaviors and logic for creatures?
    2. Can Emerald create animals can walk on land and also fly in the air like birds or marine animals can live both in water and land. They require two or even three different behavior groups, I'm using ICE and found it a bit difficult to setup un-landed creatures and the animations are not very smooth with it's movement controls. Wondering if Emerald can do better than that.
    3. I can see that Emerald has its own animal status system, how can this system act with our own character controller and custom combat system? Any integration tips in the documentations?
    4. Does Emerald has a path finding system, or should we use a third-party asset (or our own)? And does it support top path finding assets in asset store (like A* Project) and how do we integrate it?

    We are trying to make not a simple AI system, but a realistic and complex one that can let the player study, learn, adapt and exploit. But we are short handed in programmers, need something does not require scripting (which can let me, a game designer, to create complex enough AI and let our programmers to do other important things) to achieve our goal. Would like to know if we should give Emerald a try :)
     
  31. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Hey there!

    My apologies for the late response.

    1) AI can dynamically form groups. However, you cannot customize their hunting or grazing logic. If they see an appropriate target, they will simply attack or flee. AI within packs will follow the herd leader.

    2) Emerald has a wandering function that dynamically creates waypoints that the AI moves to. These waypoints don't detect changes in environments such as water, but this can be handled with Unity's NavMesh so they are avoided. Currently, water and flying AI are not supported with Emerald. However, there are plans to add these with a future update.

    3) A tutorial regarding integrating other character controller systems can be found here: http://emerald-animal-ai.wikia.com/wiki/Tutorials the full documentation can be found here: http://emerald-animal-ai.wikia.com/wiki/Documentation
    The process should be fairly similar to your custom system. Below are the typically used functions.

    Code (CSharp):
    1. EmeraldSystem.Damage((int)damageAmt); //Damages an AI
    2. EmeraldSystem.MakeFlee(Target); //Makes an AI flee from the Target
    3. EmeraldSystem.MakeAttack(Target); //Makes an AI attack the Target
    To attack your custom character controller, you can set a string within each AI that calls your custom damage function. However, this uses SendMessage so if it uses multiple parameters, you will need to call the function itself, which is easy to add into the Emerald code if needed.

    4) Currently, A* Pathfinding isn't integrated and there is no built-in pathfinding system. However, Emerald uses Unity's NavMesh system which has some pathfinding capabilities with using Unity 5.6 and above. We are currently looking into solutions for this for the next Emerald update.
     
  32. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Thanks for the reply
    For my game have creatures in water, on land and in air, I can not use Emerald if it doesn't support them in this version. I'll check back when you added these features.
    Again, thank you for your time :)
     
  33. Mighto360

    Mighto360

    Joined:
    Sep 15, 2016
    Posts:
    69
    @BHS
    Is there a expected release date for Emerald 1.4? My game needs water and air animals, so I may have to try another AI package if 1.4 is not released soon.
     
    Last edited: Aug 2, 2017
  34. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    I almost finish my game using Emerald AI and UFPS.
    The only thing that I can't make it work correctly it is the blood effect when the enemy is hit.
    I find a tutorial page with the image below
    http://emerald-animal-ai.wikia.com/wiki/Documentation?file=EffectsOptions.png
    I config my AI using the same options, but when I hit an AI enemy it did not show any blood effects. How I can make the blood effects appears?
     
  35. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Just add a Surface Identifier to the animal with Flesh Surface
     
  36. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    I add the Surface Identifier to the animal and it works, thank you @llJIMBOBll

    But I try to edit the effect and I can't modify it, which obejct I need to edit to change the blood effect?
     
    llJIMBOBll likes this.
  37. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Best way is to click on the Vp_Surface Identifier and click on the Surface Type.. If you use blood effect use Flesh(vp_SurfaceType), click on it and it should take you to the main object for the Flesh type and you can see on the object it shows the Impact FX list, depending what weapon type your using click on the BulletOnFlesh Surface type.
    That should take you to the vp_SurfaceEffect, ths is where you can change the sounds and blood fx prefab (Objects).
    Hope it helps :D
     
  38. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    It help me a lot. I find the vp_SurfaceEffect, inside I try to edit the BulletFlesh prefab, but I don't have much experience to edit this type of effect, I look for another blood effect and find one that fits perfectly in my game.
    Thank you so much @llJIMBOBll
     
  39. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    I am sorry to repeat the question. I know can be annoying but I am starting to lose my hopes.

    Is there any way to specify a turning animation in Mecanim? I checked over and over and I cannot understand.

    Thanks in advance
     
  40. bonsaisushi

    bonsaisushi

    Joined:
    May 18, 2017
    Posts:
    34
    Hello,
    I was reading in the thread that an Emerald AI 2.0 is in the works, will it be a standalone (paid) asset or just an update
    @BHS

    Also, a few more question
    1. Can I setup a behaviour like "attack on tap", making the user tap on the screen to inflict damage on the creature?
    2. The asset creates an Object or adds a Component to an existing one when using "Create Example AI"?
    3. Did you test the behaviour in an AR environment? I'm looking forward to do it myself if needed

    BTW it looks great, if it works for my project I will be really happy to buy it :)
     
    Last edited: Aug 3, 2017
  41. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Hey guys!

    There currently is no release date. However, Emerald 2.0 (recently renamed) is currently in development and our main focus until it's completed. The new version of Emerald will have water and flying support.


    Hey there!

    There is currently turning animation support for Legacy animations, not Mecanim. Emerald 2.0 will have full support of turning animations for both Legacy and Mecanim.

    For a temporary turn animation, you could create a new state called "Turn" that the walk and run states would have to go through before they play. This should give you the ability to have a turn animation with Mecanim.


    Hey there!

    Emerald 2.0 will be a free update included with Emerald.

    1) Yes, you would have the tap get the targeted AI's Emerald script and call the Damage(int DamageAmount) function.
    2) The "Create Example AI" instantiates a prefab into the scene with the given settings for demonstration purposes. This allows users to see how each AI behavior acts without having to apply their own model and animations.
    3) AR has not tested.

    Thanks! Please let me know if you have anymore questions.
     
    bonsaisushi likes this.
  42. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hey, thanks a lot for the answer! Just a small question. How Emerald realize that the Turn State is finished? It is automatic? How do you suggest to set this Turn State?

    Thanks
     
  43. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    You're welcome.

    If your added Turn State is ran through your Walk or Run States, it should only play once. So, it should be automatic. The Turn State doesn't need to be set, it should just be triggered from the Run or Walk state.

    We will be looking for beta testers for Emerald 2.0 soon. If you are interested, just let me know and you can test out the version that is currently being worked on. It has turn detection that can detect if the AI is turning left and right. You can customize the animations for both directions.
     
  44. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Hey everyone!

    What we previously mentioned as Emerald 1.4, will now be called Emerald 2.0. This is due to the amount of work that needs to be done to drastically improve the quality and functionality of Emerald. We appreciate everyone's patience as we continue to develop Emerald 2.0. Most importantly, this update will be free to all previous Emerald owners.

    Emerald 2.0 is being rewritten from the ground up. This is allowing us to make huge improvements with how the overall behaviors are implemented as well as drastically reduce the code length. An AI's behavior can be changed at any time and the AI will react accordingly. Behaviors are much more realistic and have more options to suit your game's needs. Previous versions of Emerald made things more complicated as the code was lengthy and convoluted.

    Now let's get to the details of Emerald 2.0! Below is everything that is implemented so far. There is much more to come. All the features from the previous version of Emerald will also be implemented such as dynamic herds and packs and breedable AI. To reassure users who want a unique AI system, this is still our goal. We are simply improving Emerald's core and its behaviors while expanding its versatility. Demo videos of the new features and improvements will posted within the next couple of days.

    Improved Behaviors
    Passive - Will wander around unless attacked. When attacked, it will take action according to its Confidence Level

    Passive Confidence
    • Coward - Flees when attacked
    • Brave - Fights back, but flees after a set amount of health is lost
    • Foolhardy - Fights back and will continue to fight until they are dead
    Aggressive - Will wander around until it detects a target either by sight or trigger

    Aggressive Confidence
    • Coward - Fights defensively, but flees after a set amount of health is lost
    • Brave - Fights aggressively, but flees after a set amount of health is lost
    • Foolhardy - Fights aggressively and will never flee
    Companion - Will follow around their follow tag and attack anything within their target tag list. Companion AI do not use the Confidence system.

    Cautious - Wanders around until confronted by a target. When confronted, it will take action according to its Confidence Level

    Cautious Confidence
    • Coward - Flees when a target is detected either by sight or trigger, which are dependent on the Detection Type.
    • Brave - Will stand their ground for a set amount of seconds. If a target is still within range after the set amount of seconds, they will fight. Once their health reaches a set amount, they will attempt to flee.
    • Foolhardy - Will stand their ground for a set amount of seconds. If a target is still within range after the set amount of seconds, they will fight and continue to fight until they are dead.
    Line of Sight
    • Line of Sight implementation allows AI to only attack or flee from targets that are visible from the AI's line of sight. AI will no longer be able to detect you through walls or objects. This also allows users to implement sneak mechanics to characters.
    • If Line of Sight is enabled, AI will go into "Alert Wandering", if a target is within range, but not visible. An option has been added allowing AI to have specific settings when in Alert Mode which can change their wandering range, wandering frequency, idle animation, and more.
    • The line of sight detection can be adjusted for each AI to best match the model.
    • An option has also been added to not use the line of sight feature for those who want more of a casual RPG target detection. This option will simply use a trigger detection.
    Improved AI Actions and Functionality
    • AI will now turn properly and consistently. AI can independently detect if they are turning left or right. The ability to play an animation according to the direction that the AI has also been added.
    • AI have a customizable delay, while in fight mode, allowing them to take brief pauses before moving to the target position and attacking their target. This gives a AI a more realistic feel when in combat. A similar technique is used in other games. However, this feature is completely optional.
    • AI with an active target, with a Cautious behavior and Brave or Foolhardy confidence, will look at their target. They will not attack until their "Cautious Seconds" have been reached. During this time, AI will have the option to play a warning animation and/or sound. After this time has been exceeded, AI will be switched to the Aggressive behavior and attack their target. This allows AI the action to act territorial.
    • Improved attack function is much more reliable. The run attack is also calculated within this function, if enabled.
    • Tons of new API to make implementing Emerald with custom scripts and game mechanics much easier.
    Improved Animations
    • Emerald 2.0 has improved animation blending making animations play more reliably and blend with the AI's current actions/states. More animations have also been added, which have been explained above.

    Suggestions and Feedback
    If you have any suggestions or feedback, please post them here.

    Beta Testing
    If you are interested in being a beta tester for Emerald 2.0, please private message us your Emerald AI Invoice Number. The first beta test for Emerald 2.0 will be available for testing within the next couple of weeks.
     
    Last edited: Aug 7, 2017
  45. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Hi Sir, Amazing system by the way :D

    I'm wondering is there something my script can listen to or check to see if and AI is currently in combat with the Player?

    This is so I can play some battle music while in combat :D

    Thank You Jim
     
  46. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    If BHS doesn't answer right away I can find this out for you. I did exactly this with Emerald AI for a project I was working on a while ago. I don't have the scripts handy though so I can't remember exactly what I did. To the best of my recollection I wrote some code that added enemy AI to a list of targets whenever they were within a certain range. If they went out of range then I would remove them. Then my code would check those enemies that are within range and checked for some Emerald AI attribute to determine if they were actively in battle stance or something like that. If they were then I'd fade in a random selection of battle music. Then if they were all out of range or no longer in battle stance (or whatever it was) then I'd initiated a cooldown period (about 5 seconds) and then fade out the battle music.
     
    llJIMBOBll likes this.
  47. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Hi Sir, Thank you! That is a really good idea I will probably go with :D Today I wrote an audio manager which i can play some random music from a list and fade in / out.

    Thank You Jim :D
     
    magique likes this.
  48. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    Great news BHS, sort of. Beta testing in a couple of weeks. 1.4 has been a long time coming. What does this mean for a 2.0 release date? Is there a link available to a comprehensive feature/fix list, as there was a LOT of fixes and features promised to be layered into 1.4.

    Impatiently waiting for 2.0...
    Mark
     
  49. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @llJIMBOBll I checked my code and the thing that I used to determine if an enemy is actively targeting a player was the huntMode parameter. So, as long as the AI wasn't dead, was in huntMode, and in range then the battle music would play.
     
    llJIMBOBll likes this.
  50. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Here is something I found Online and modified, it will check for targets of a layer in range and add the gameobject to a list. From the list you can do stuff.

    Here i've set it up to check for AI that is in Range and is in "HuntMode" and if it's the player its hunting "IsPlayer". If the AI "IsDead" then it will stop audio playing, or if the AI isn't in Range then it will stop! (Hopefully checking correct bools

    If the AI is Hunting the Player then it will choose a random audio clip to play and play it.
    (not setup fading in out audio yet, i'm not at my main computer with the audio manager I wrote and will use that to play my music.) If someone wanted to you can easily add in Fade in / out :D

    If there is a Dead Ai and a Alive AI it will Play Audio.

    It will also draw a gizmo in the editor for the Range.

    Original Author Code I found, Link! https://forum.unity3d.com/posts/2891575 Credit to jeffreyschoch Thank you!



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Linq;
    5.  
    6. public class Jims_AIInRange : MonoBehaviour
    7. {
    8.     [Header ("Target Setup!")]
    9.     public float Range = 0f;
    10.     public int MaxTargets = 0;
    11.     public LayerMask LayersToCheck = 0;
    12.     [Space (10)]
    13.  
    14.     [Header ("Check For Targets In Range!")]
    15.     public float WhenToStartToCheck = 1f;
    16.     public float HowOftenShallWeCheck = 1f;
    17.     [Space (10)]
    18.  
    19.     [Header ("List Of Targets In Range!")]
    20.     public List <GameObject> TargetsInRange;
    21.     [Space (10)]
    22.  
    23.     [Header ("Audio Setup!")]
    24.     public AudioSource AudioSource = null;
    25.     public AudioClip[] AudioToPlay;
    26.     public float Volume = 1f;
    27.     public float NOTSETUPYETFadeInTime = 2f;
    28.     public float NOTSETUPYETFadeOutTime = 4f;
    29.  
    30.  
    31.     void Start ()
    32.     {
    33.         InvokeRepeating ("FindTargets", WhenToStartToCheck, HowOftenShallWeCheck);
    34.     }
    35.  
    36.     private void FindTargets ()
    37.     {    
    38.         // get any colliders in range and on the layermask
    39.         Collider[] targetCols = Physics.OverlapSphere (transform.position, Range, LayersToCheck);
    40.  
    41.         // if more than maxTargets were found
    42.         if (targetCols.Length > MaxTargets)
    43.         {
    44.             //sort by distance (uses System.Linq)
    45.             targetCols.OrderBy (hit => Vector3.Distance (hit.transform.position, transform.position));
    46.         }
    47.  
    48.         // this is a list that we will populate with targets in range
    49.         TargetsInRange = new List<GameObject> ();
    50.  
    51.         // populate the "TargetsInRange" list, will only add up to "MaxTargets" number of objects
    52.         for (int i = 0; i < MaxTargets; i++)
    53.         {
    54.             // make sure "i" doesn't go past the number of targets in range
    55.             if (i < targetCols.Length)
    56.             {
    57.                 TargetsInRange.Add (targetCols [i].gameObject);
    58.             }
    59.             else
    60.             {
    61.                 //Stop Audio if not in Range!
    62.                 if (targetCols.Length == 0) {
    63.                  
    64.                     if (AudioSource.isPlaying)
    65.                         AudioSource.Stop ();
    66.                 }
    67.  
    68.                 // stop the loop if there are no more hits
    69.                 break;
    70.             }
    71.         }
    72.  
    73.         foreach (GameObject target in TargetsInRange) {
    74.  
    75.             //DO STUFF HERE!
    76.  
    77.             //Checking if enemy is Hunting and if Hunting Player!
    78.             if (target.GetComponent<Emerald_Animal_AI> ().huntMode == true
    79.                 && target.GetComponent<Emerald_Animal_AI> ().isPlayer == true
    80.                 && target.GetComponent<Emerald_Animal_AI> ().isDead == false) {
    81.  
    82.                 if (!AudioSource.isPlaying) {
    83.  
    84.                     //Choose a Random Clip to Play from the list!
    85.                     var RandomClip = UnityEngine.Random.Range (0, AudioToPlay.Length);
    86.                     AudioSource.PlayOneShot (AudioToPlay [RandomClip], Volume);
    87.                 }
    88.  
    89.                 //Cancel Stopping Audio If there is another Enemy In Range Hunting The Player!
    90.                 return;            
    91.             }
    92.  
    93.             //Stop If Enemy Is Dead! RIP!
    94.             if (target.GetComponent<Emerald_Animal_AI> ().isDead == true) {
    95.              
    96.                 if (AudioSource.isPlaying)
    97.                     AudioSource.Stop ();
    98.             }
    99.         }
    100.  
    101.     }
    102.  
    103.     //Draws Range Gizmo In Editor!
    104.     private void OnDrawGizmosSelected ()
    105.     {
    106.         Gizmos.color = Color.green;
    107.         Gizmos.DrawSphere (transform.position, Range);
    108.     }
    109.  
    110. }
     
    Last edited: Aug 11, 2017