Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by soft_sound · Feb 04, 2015 at 08:27 PM · aipathfindingbehavioursteeringavoidance

Avoidance Behaviour

Hello. I would like some general tips or perhaps overall concepts to avoidance behaviour. I currently have come up with a somewhat working solution involving mirroring what I want to advoid, but if you couldn't guess, that only half works as mirrors are like that. I've heard about steering behaviour but it sounds more complicated then I want, but if there isn't any better way I suppose it could work. Path finding is also related to avoidance behaviour but with my paths changing so often I'm not sure if that is the best method.

Currently for some quick advoidance behaviour I have been using this code snippet I came up with.

transform.position = Vector3.MoveTowards(transform.position, -myPlayer.player.position, moveSpeed * Time.deltaTime);

I know that getting by normalizing the transform.position and player position I can tell if the player is moving closer to me as the normalized variable remains the same... But I'm not sure what to do with that, I've never taken any decent math classes....

direction = transform.position - myPlayer.player.position; direction.Normalize();

if I could somehow check if I'm getting the same result from normalize constently and then reverse my direction, that would probably solve my whole issue. Maybe...

Any advice or perhaps websites that go into detail on this sort of thing? This avoidance behaviour will be used on a large group or herd of objects to advoid other herds and enemies.

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 AlwaysSunny · Feb 04, 2015 at 11:26 PM 1
Share

Heads up, this kind of open-ended question belongs in the scripting forum.

Avoidance behaviors are a sub-category of steering behaviors. Definitely a little math for you, but luckily, the computer does the lion's share of the work. ;)

There are many approaches to setting up avoidance mechanics, each with pros and cons. The fundamentals are simple enough. Steering around static obstacles is pretty straightforward - steering around other actors gets... interesting. No cookie-cutter solutions, I'm afraid, unless you can find a good steering library. (I don't like those I've found).

This is the quintessential resource for simple steering behaviors. Helped me immeasurably when I was where you're at: http://www.red3d.com/cwr/steer/

avatar image soft_sound · Feb 05, 2015 at 03:06 AM 0
Share

Thank you, I would have marked this as an answer if you posted it as such. It looks like if I pick apart UnitySteer and this I might get the behaviour I'm looking for. I'm trying to have a shepherd steer a flock of sheep away from enemies and such. It's a complicated AI project but so far it kinda works...

2 Replies

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

Answer by soft_sound · Feb 05, 2015 at 04:55 PM

Actually, I got my code to work. Steering Behaviours& Avoidance

I used this as my reference and converted it over to C#. It was really simple like I thought it would be. I was quite close!

 public Vector3 velocity;

 public Vector3 desired_velocity;

 public Vector2 d_velocity;

 public Vector2 steering;

 public Vector3 max_velocity;

.....

 if (flee)
     {
         if (Vector3.Distance(transform.position, player.position) < 5)
         {
             desired_velocity = Vector3.Normalize(transform.position - player.position);

             desired_velocity = Vector3.Scale(desired_velocity, max_velocity);

             d_velocity = new Vector2(desired_velocity.x, desired_velocity.y);

             steering = d_velocity - transform.rigidbody2D.velocity;

             transform.rigidbody2D.AddForce(steering);
         }
     }

Anyway hope this helps anyone else!

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 DanSuperGP · Feb 04, 2015 at 11:29 PM

" I've heard about steering behaviour but it sounds more complicated then I want, but if there isn't any better way I suppose it could work. "

Steering behaviors are about the least complicated of navigation systems. If you don't want to deal with implementing them yourself you could just use UnitySteer

http://arges-systems.com/blog/category/unitysteer/

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 soft_sound · Feb 05, 2015 at 03:03 AM 0
Share

Navigation systems aren't all complicated, simple node based paths and wandering systems are pretty simple, just a few lines of code. Following objects can be simple within a certain context. It seems though Unitysteer has some examples in the advanced section I can hopefully use so I think I'll pick those apart and see what happens. Thank you.

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

23 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

Related Questions

Attacking units surround attacked building properly? (New solution, or fix to Nav Mesh?) 0 Answers

What easiest way to emulate local avoidance? 1 Answer

How to combine NavMesh Agent with Character Controller 0 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


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