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 squid808 · Mar 02, 2012 at 05:26 AM · c#aiavoidance

Get AI behavior to avoid enclosure walls?

Hi all. I'm trying to work out a concept here and am stuck on what I hope is a somewhat simplistic answer. Working in the X,Y planes only I have a force-driven AI ship wandering around an enclosed area (the black square in the picture). My goal is to make the wandering a bit more intelligent, avoiding the edges of the enclosure. For the record, the enclosure rotates around Z and has thin collision boxes lining each edge. Also, I'm trying to find a solution that will work for enclosures that aren't always going to be the same shape, so also for a circle or a star or something.

In this pic, the ship is the tiny dot near the center with the red, green and blue gizmos sticking out.

http://i41.tinypic.com/11wdmc3.png

My first thought was to make a collision trigger area that would tell the ship 'hey, you're getting too close to the wall'. That's easy enough, but I can't seem to find a way to get the closest wall, find a vector perpendicular to that wall. If I could do that, I could say something like apply force (1/distanceToWall)*RepellingForce or something (pseudo code, of course).

My second thought was setting up individual trigger rectangles for each wall, always putting a force on any ship it affects. That kinda made sense since even when it rotates the local coordinates and axis would rotate with the enclosure, so the top trigger rectangle could apply the force in the -transform.up direction. I still need to figure out distance from the closest point of the wall, though.

Third thought was strictly using something like a raycast, but again, not sure how to find the closest bit of wall relative to the ship.

Any thoughts? I checked out UnitySteer, but wasn't able to get it avoiding anything other than spheres. I'm not sure if I should be looking in to pathfinding meshes and all that jazz? Best I could find for the 'closest to object' was this, but it requires having enough vertices to track. These walls have... 2. One at each end.

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

1 Reply

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

Answer by Berenger · Mar 04, 2012 at 12:50 AM

The same idea than the raycast, but more fit to your situation, Physics.OverlapSphere. Call that around the ship, then finding the closest one will be easy (use sqrMagnitude, not the classic magnitude). An array is always returned, so you can check if Length == 0.

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 squid808 · Mar 07, 2012 at 04:26 AM 0
Share

Thank you for this help!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How do i get the IsPathPossible() function to ignore some nodes using Astar Pathfinding Project 0 Answers

How do i get the IsPathPossible() function to ignore some nodes using Astar Pathfinding Project 0 Answers

Basic 2d AI follow? 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