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 kevinf63 · Jun 09, 2013 at 08:59 PM · instantiateainavmesh

Instantiate AI characters over Navmesh area?

Hi there, as the above question states, is it possible using Unity library methods or otherwise to instantiate, in my case randomly generated AI characters, but they only spawn over the area the Navmesh covers?

I.E. The AI are a crowd of people in a city, but I don't want them to spawn in for example the middle of the road, which I have specified as non-walkable to the agents/characters in the road's navigation layer.

Similarly what would I do to randomly change the setDestination of the AI agent to keep within the bounds the navmesh covers? I hope I've helped you grasp the situation! :D

This is probably quite simple, but then again, I could be very wrong.

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 kevinf63 · Aug 02, 2013 at 05:09 PM 0
Share

Does nobody have an answer? I hate to do this but... BU$$anonymous$$P.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Toli · Aug 12, 2013 at 01:58 PM

I've been working on some similar ideas and looking at AI code, so i can't quite help with code examples, but here's how i'd start it off. remember to start small, but plan big.

With multiple AI's, use a pool or spawn manager.

which would manage the variables for: starting point(s), a route or unique characteristic /waypoints to use for each spawn. a maximum number of mobs to spawn.

and, possibly some other characteristics you'd want to alter, like

textures for spawning a variety of mob types or some random variables for color/shape/size

max idle time, max walking time, speed, accel, turning speed, health, audio effects to use for idle/walking

etc.

a spawn manager can have this all 'baked in' with variables, or you could find a spawn manager, edit it to include these variables.

some AI scripts also come with a few examples of a pool manager i.e. tower defense games have some good examples of spawn and pool managers to handle timers, movement, re-navigation, etc. the pool manager would handle timers, navigation updates in bulk and save some performance issues with so many AI's, pool managers also make a good place to put in any collision tests and so on.

it may require some significant testing ... sic.

if all the mobs share one general path, you can also optimise the calculations and cache waypoints or create "fuzzy" waypoints, between A and B or randomly move the end point to a position near to B, so they don't all stand on one spot to turn.

the pool would set mobs to come out from say, 2 - 4 different positions, the mobs will each pick a navigation node, then walk from a list of defined spawns or walking points in the city, maybe A to G, and loop either on an idle, or a walk cycle. (or just have them walk on the navmesh around the city full time.)

alternatively, you could spawn and despawn characters off-camera as well, by checking that the spawn point is safe.

first, spawn an initial, hidden object on the navmesh, run some checks to see if it's colliding, near to any other AI's, or in range/raycast range of any other objects like the camera, and if it's all clear, spawn the AI prefab in the selected location, or if a character is stuck, can't navigate, or they have been in the same position for too long, have it idle, then respawn in a new off-camera location.

etc.

for more natural behavior, a few random numbers or timers can help. each update it can choose a new route to take once it gets to the destination, or have them pick a new waypoint after 20-40 seconds. with an idle/walk timer, it will walk for a while, stand, choose a new waypoint after it has idled, walk towards it, repeat.

collision, could cause a reset of the timers and the destination of the AI, so they could walk to the same destination, one collidee' would idle, the other collidee would choose a new destination, etc.

this way, each AI will properly mill around, and change direction every so often. this would keep the AI's from becoming too similar or chained together, you probably should keep the idle timer low, and the walk timers longer, say 4s idle /20 seconds walk, or base it off the duration of the idle animation, etc.

a pool manager can also handle enemy and player interaction/radius, or scatter/scare if you want a more GTA iV like NPC to start running when they take damage, see the player is in range, trigger the scream/terror audio, etc.

you get the idea.

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

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

15 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

Related Questions

how to instantiate prefabs around the player but when there is an object in that position it dont instantiate 1 Answer

Make AI walk on instantiated platforms ? 0 Answers

how to get AI to move to the closest of the same object? 0 Answers

NavMesh link does not connect properly on runtime 1 Answer

How to make AI walk around ingame built walls? 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