Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ayyylex · Aug 15, 2016 at 04:33 PM · c#enemy aiadvanced

Advanced AI C# (Follow & Attack)

So I want to make a advanced AI monster that will basically follow you and once close enough stop to attack you.

Basically I would like to know what is the best way to go about making a monster that at first will stand still, then once the player gets closer it plays an animation and it remains standing still BUT starts rotating towards you, always trying to face you. Then once you get even closer it will stop doing the other animation and start doing a walk animation & move towards you. If you turn around it will charge you (preferbly a one time action) by increasing its speed and changing to a run animation. Once it is near you it will stop moving and attack you (dealing damage + animation).

Ive tried my best to search through alot of things but most things are just "simple AI" that is just too simple for this, and then there is the official unity tutorial which is wayy too advanced for this.

I have all my models and animations self made so all I have to do is script it.

So any suggestions, ideas or references to help me understand how to script this are welcome.

Or if you are willing you can create a basic template that might be like what i want.

Thank you for reading.

Comment
Add comment · Show 2
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 LLIV · Aug 15, 2016 at 07:00 PM 0
Share

I would suggest watching the entire unity tutorial. It most likely is exactly what you need. It may seem way to advanced (it may be) but from personal experience I can tell you that the tutorials can help you write your own scripts. So even if you don't want to make something nearly as complex you should still be able to learn something from it. Also in regards to writing simple AI vs advanced AI what you want is very specific and you're not likely to find any tutorial that has exactly what you want. Go find an example script that's way to complex for you (Like the Unity Tutorial) and dumb it down to fit your needs, you'll learn a lot and trust me it'll be faster than writing your own script if you don't know what you're doing.

avatar image ayyylex LLIV · Aug 15, 2016 at 08:57 PM 0
Share

Yes I know, I will try to follow along and see, thank you.

3 Replies

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

Answer by ArchoTek · Aug 15, 2016 at 08:04 PM

There's two options here:

  1. Get someone to write you pretty much the entire thing so you can continue with your game, only to come around with a new issue the next day...

Or 2. Suggest ways for you to get the hang of programming yourself.

The second one seems wiser to me. In order to write the AI you want to write - I'm sorry, but really - you'll have to start with lame simple AI. If AI at all. I'll give you some leads for the AI, but I won't tell you how to do it exactly.

Track distance between the player and the AI using Vector3.Distance, if that distance then drops below a set variable (let's call it f1), you set a boolean true - also in an attached animator component using GetComponent().SetBool(), and then if the bool is true run a part of the script which sets the destination (using integrated NavMesh components) of the 'monster' to the player's location.

I'm guessing you don't know how to do any (or most) of this -- don't get me wrong, I'm not trying to burn you, but I'm trying to make you realize that having people write stuff for you and not learning yourself will only bring pain in the long run.

Follow tutorials, get the hang of coding and you'll be able to write the complex AI from the logic you've got in your head. If you need something, come up with it and write it, don't keep trying to get it from another place.

You'll get there if you keep trying, and always remember... Google is your friend! (Referring to the learning process, not this specific issue...)

Comment
Add comment · 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
0

Answer by ayyylex · Aug 15, 2016 at 08:56 PM

@ArchoTek Thanks for the reply, Ill try to follow everything you said tomorrow since its late for me.

I certaintly have been doing alot of googling and mostly have figured things out myself, but AI is obviously a bit harder then what i have been working with, especially the multiple stage AI I am trying to achieve, though I will probably be happy enough if it alteast does half of the things I want it to.

Again, Thanks, Ill follow what you said and if i eventually reach a semi-solution Ill make this answer as the main solution.

Comment
Add comment · 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
0

Answer by ericbegue · Aug 16, 2016 at 08:16 PM

If you want to write advanced AI, you might be interested to have a look at Behaviour Tree (BT). It comes in handy for dealing with complex AI: because of its hierarchical nature, BT scales really well as the AI grows in complexity.

If you are looking for a BT framework, have a look at Panda BT. The package contains several examples, including an idle-chase-attack AI. I'm the author, so you can contact me directly if you have any question regarding this tool or about Behaviour Tree in general, I'd be glad to help.

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 ayyylex · Aug 17, 2016 at 10:35 AM 0
Share

Thanks, Ill take a look into that too.

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

219 People are following this question.

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

Related Questions

What are the best practices of designing code architecture? 3 Answers

How to have multiple enemies (currently having to kill them in order) 1 Answer

Random Number keeps generating over and over 2 Answers

Boss ai help EoW 0 Answers

Enemy animation gets weird when going to set position 0 Answers


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