Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by AniMerrill · Mar 15, 2012 at 08:47 PM · aisimplebest practicesartificialintelligence

AI in Untiy, best practices

THIS IS NOT A REQUEST FOR AN AI TUTORIAL. (sort of)

Likely, I'm just asking the wrong question. I have a pretty good grasp of how AI works, but I'm a still not completely sure how to write it so that its eloquent and modular. Basically I want to avoid having separate AI code for every enemy or character in the game but I'm having a hard time finding a good way to write it.

What I want is basically a singular script that is the base for all characters in, but then you can add to a list or node the specific behaviors that enemy or character has. Things like idle behavior, way-point patrol, pursuing and attacking player, etc. That way I can focus on making more verbose behaviors rather than having to create possibly hundreds of unique AI scripts for all the enemies in the game (since likely, many of them will have similar behavior patterns MINUS one or two things that make them unique).

I saw something like this demonstrated a while ago in a YouTube video but I can't for the life of me find that video again. So what I want to know: is this the best practice in Unity? If so, what are some suggestions (or tutorials specifically about this) that you can give me about writing behaviors this way? If not, what would be a better way to go about it?

Thanks, sorry for the lengthy post.

EDIT: It is also sort of my goal to avoid AngryAnt's behave. I'm both trying to grow as a programmer as well as uncomfortable with his licensing agreement, so I do not wish to use Behave for my solution.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeveshPandey · Mar 26, 2018 at 05:07 PM 0
Share

Here is a good plugin, it may help you.

https://www.assetstore.unity3d.com/#!/content/87744?aid=1101l34jr

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by apollyonbob · Mar 16, 2012 at 12:51 AM

I see that you're trying to avoid AngryAnt's behave, but are you trying to avoid Behavior Trees? If not: http://aigamedev.com/insider/article/behavior-trees/ - It requires a signup, but it's free to watch that particular video. That's an excellent description of Behavior Trees and how they work.

My approach to it was to create an abstract Behavior Tree which could be overridden for specific purposes. So for "Shooting" for instance, I have a ShootTree: BehaviorTree. Then within that Tree, I create the nodes in the Start(). Each Node can be the various types of Behavior Tree nodes (Parallel, Serial, etc - a full discussion of Behavior Trees is out of the scope of this answer) which all implement the same Interface. Then when I create node, I inject the logic into the node as I'm creating it, including PreConditions, PostConditions, and the actual node logic. Then the tree basically ticks each node, checks the result, etc. Each Tree is also a IBehaviorTreeNode so that you can nest trees within trees. If you're worried about repeating logic, you should be able to stick that logic into a static class. However, I have to warn against this just because the reality is you will probably need to customize it per-enemy. It's good enough to have the framework be modular and reusable, if you try to go too deep, you'll drive yourself crazy.

I don't have a ton of implementation detail here because it's a pretty complex subject, as you can imagine.

The most difficult part of any object oriented or design pattern based approach to anything in Unity is that so much of the time if you want any design-time access to the thing you have to make it a MonoBehavior, or you'll end up going crazy with factories.

Abstract classes are possible, but for the Trees, your base class needs to be MonoBehavior. This so you can just stick the tree on the GameObject and tweak values in the Editor.

Anyway, just some things I've learned.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AniMerrill · Mar 16, 2012 at 12:58 AM 0
Share

Yeah, shortly after posting this I started researching behavior trees (because I figured that the Angry Ant guy must know what he's doing, but I just don't want to agree to his licensing). I think I understand the basic premise, my only qualm is I'm really confused how to implement. I'm watching an hour long lecture http://www.youtube.com/watch?v=n4aREFb3SsU to try and absorb some of the implementation techniques, but I am a little worried about how to transfer this over to Unity.

I'll have to watch the video you gave me (I only saw the first of three parts of that because I hadn't signed up yet). Thanks for the answer.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating an Enemy Jet AI 1 Answer

BDI Agent Programming in Unity3D 1 Answer

need a logical tip for AI 2 Answers

My model from Blender does not follow the AI script properly! 2 Answers

Tutorials for AngryAnt's Behave 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges