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
0
Question by TifaOng · Sep 18, 2013 at 08:17 AM · c#positionai

AI Patrolling

I have created an enemy to follow the player whenever the player is within range. But after the player went out of range, the enemy does not move back to its own default position for patrolling.

I have 1 questions here, 1. How to create a patrolling AI? 2. Can I know how to do set the enemy to go back to its default position for patrolling?

Thanks!

Comment
Add comment · Show 6
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 DaveA · Sep 18, 2013 at 08:30 AM 0
Share

Google 'state machine'

avatar image TifaOng · Sep 18, 2013 at 09:35 AM 0
Share

I know what's a state machine, but I do not know how to implement in Unity C#. Thanks for the info.

avatar image ShadoX · Sep 18, 2013 at 10:15 AM 0
Share

Isn't this a matter of checking if the AI is still following the player and if it isn't, send it back to the patrolling path? In which case you would just have to make sure that the AI can find the way back assu$$anonymous$$g that there might be obstacles in the way which would mean that you have to use pathFinding.

avatar image TifaOng · Sep 19, 2013 at 02:09 AM 0
Share

ShadoX, do you have any idea how do I program for the AI find it's way back?

avatar image ShadoX · Sep 19, 2013 at 06:54 AM 1
Share

You could try checking out http://unity3d.com/unity/quality/ai, http://arongranberg.com/astar/features or http://hutonggames.com/playmakerforum/index.php?topic=1975.0

I'd suggest to simply look for some pathFinding solutions for Unity. Those are just 3 that I found after a couple of seconds, but I'm pretty sure that usually when you do look into pathFinding that you most probably will end up finding just a couple of algorithms anyway.

Sorry for not providing more info, but I haven't touched this subject yet including those algorithms.

Show more comments

1 Reply

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

Answer by RyanZimmerman87 · Sep 19, 2013 at 02:41 AM

A really easy way to do this is to create a vector 3 position for the enemy on Start()

If the enemy is no longer following the player simply turn them around back to this position. If the enemy is patrolling too far from this position simply turn them around back to this position. That's probably the simplest way to do this.

So whenever you want them to return to the start point whether it be because the player is out of range or they are too far from the start point or any other variable you want, you can use:

transform.LookAt(enemyStartingVectorPosition);

And then have the enemy move in this direction. If you want them to follow specific patrol routes or navigate around walls it will require additional logic.

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 TifaOng · Sep 20, 2013 at 05:10 AM 0
Share

I see, okay. I'll try that out. Thanks!

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

18 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

Related Questions

Operator `+' cannot be applied to operands of type `UnityEngine.Vector3' and `int' 1 Answer

Multiple Cars not working 1 Answer

addition of vector3 1 Answer

looking to make for a zombie script AI,navmesh or not? 2 Answers

How to Maintain Y Position? C# 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