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 SirMcsquizy · Apr 09, 2014 at 05:03 PM · c#ai

How to make AI wonder about? C#?

Hi There!

So, I was wondering how to make a (for example) Monster wonder around until it saw a player. Then Start walking towards you. I have the walk towards part, but I dont know how to make them just walk around!

If you could help that would be great!

Thanks

-Sir

Comment
Add comment · Show 5
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 putlucky · Apr 09, 2014 at 05:06 PM 0
Share

Can you show us what you have so far?

avatar image thomasindustry · Apr 09, 2014 at 06:26 PM 0
Share

You will probably need some form of a pathfinding algorithm in place if you don't already have one.

avatar image TonyLi · Apr 10, 2014 at 03:45 AM 0
Share

For wandering, you don't need pathfinding. A simple steering behavior will do.

avatar image fafase · Apr 10, 2014 at 04:37 AM 1
Share

I would recommend waypoint ins$$anonymous$$d of pure wandering. Nothing just wanders, it always has a destination, so should your NPC. Wandering agent will probably end up with non-human behaviour like heading towards a zone where there is nothing to do. So waypoint coupled with steering behaviours to avoid obstacles would be better.

avatar image TonyLi · Apr 10, 2014 at 05:57 PM 0
Share

I agree with @fafase -- waypoints are a good, too. It really depends on your needs. If you go with waypoints, consider choosing them randomly so it doesn't look like the monster is on a fixed track.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by TonyLi · Apr 09, 2014 at 05:33 PM

Game Development @ Tuts+ has more than you'd ever want to know about wandering:

http://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-wander--gamedev-1624

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 kyrasharma1092164 · Feb 15, 2021 at 11:07 AM

it is really easy to do so;- 1- make a cube and remove the mesh render component, now create your monster and give it nav mesh agent component, finally create a c# script and set the monster destination to your cube.

code:-

          using UnityEnigne.AI; 

          public NavMeshAjent myAjent; //your monster, make sure it has nav mesh ajent
          public Transform Ajent_Destination;// your cube
          public Transform temp_playerDestination;// you i mean the player

          private bool isChasing_PLayer = false; 


          void Update()
          { 
             myAjent.SetDestination(Ajent_Destination.position);
            if(isChasing_Player == true)
              {
                    myAjent.SetDestination(temp_playerDestination.position);
               }
             else
              {
                  myAjent.SetDestination(Ajent_Destination.position);
               }
           }


         void OnColliisonEnter(Collider other)
         {
               isChasing_Player = true;
          }


Now we only need to teleport the cube , make sure it has box collider with is trigger set to true make another c# script name it as Collide and ,,,,,

code:-

        public int min_X = 0;
        public int max_X = 0;

        public int min_Z = 0;
        public int max_Z = 0;

         void OnColliisonEnter(Collider other)
         {
             this.gameObject.transform.position = New Vector3(Random.Range(min_X , max_X) , 0 /*you can modify this thing by creating min,max variables for Y*/ ,Random.Range(min_Z , min_Z ));
          }


And you are good to go, hope this works I haven't tested this script in unity so please just check for spelling cause this surely goanna work , leave the comments for any suggestion or query well this is my first ever unity solution and I am programming for a month now!!!!

Comment
Add comment · Show 5 · 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 AbandonedCrypt · Feb 15, 2021 at 12:43 PM 1
Share

it's Agent not Ajent

avatar image kyrasharma1092164 AbandonedCrypt · Feb 16, 2021 at 01:10 PM 0
Share

sorry for that also make to write OnTriggerEnter instead of OnCollisionEnter

avatar image kyrasharma1092164 AbandonedCrypt · Feb 16, 2021 at 01:12 PM 0
Share

did it helped you????

avatar image AbandonedCrypt kyrasharma1092164 · Feb 16, 2021 at 01:15 PM 0
Share

I didn't ask this question, I'm writing my own pathfinding solutions

Show more comments

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

26 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

Related Questions

Multiple Cars not working 1 Answer

AI in unity, need help 1 Answer

Distribute terrain in zones 3 Answers

[C#]OnTriggerExit set Collided false ??? 1 Answer

Make player not be seen by AI, when player in foilage and shadows. 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