Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 hm5k · Dec 18, 2019 at 04:55 AM · pathfindingrtspathing

Collision Avoidance causes jiggling

Hello! I've got a lot of C# experience but am fairly new to pathing and unity.

My local avoidance code looks like:

 public Vector3 LocalAvoidance(Vector3 heading)
 {
     Vector3 avoid = Vector3.zero;
     foreach (var unit in this.teamManager.TeamUnits)
     {
         if (unit == this || unit.enabled == false) continue;
         
         var dist = Vector3.Distance(unit.transform.position, this.transform.position);

         if (dist < radius * 2)
         {
             avoid += this.transform.position - unit.transform.position;
         } 
     }

     heading = heading.normalized + avoid.normalized;
     
     // no modification necessary for flocking behavior
     return heading;
 }



And my turning code looks something like:

     Vector3 heading = GoalPos - transform.position;
     Vector3 newHeading = LocalAvoidance(heading);

         var newRotation =
             Quaternion.RotateTowards(
                 transform.rotation,
                 Quaternion.LookRotation(newHeading),
                 turnSpeed);

         transform.rotation = newRotation;

I'm guessing I'm supposed to "remember" what I'm avoiding rather than having a hard distance check.

The avoidance function is influenced by a Boids tutorial I went through the other day, but I'm obviously still missing a few bits.

Thank you for any help!

Issue

issue-shrink.gif (330.3 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by medinaline · Dec 18, 2019 at 04:59 PM

Could it be as simple as a bool isAvoiding property on the object, to tell it to behave differently for the number of frames it takes to get past the obstacle it's avoiding? Then you could check isAvoiding before assigning the newRotation. That would keep it from turning into the obstacle every frame before turning away (jiggling).

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 hm5k · Dec 19, 2019 at 01:11 AM 0
Share

I'm attempting to avoid some of the more "manual effort" situations where values will have to be routinely tweaked, worry about framerate, or otherwise be non-mathematical in nature.

The root cause is something to do with a lack of understanding regarding avoidance so tweaking it to get a temporary fix isn't ideal I$$anonymous$$O.

avatar image
0

Answer by hm5k · Dec 19, 2019 at 01:19 AM

I've found a reasonable approximation of the correct solution, but not quite good enough I'd want to accept this as the answer to my question.

I've added a multiplier that allows me to linearly extend the distance to avoid entering and exiting the avoidance area, code below:

 heading = heading.normalized + avoid.normalized * AvoidanceMult(temp);
 
         // no modification necessary for flocking behavior
         return heading;
 
         float AvoidanceMult(float dist)
         {
             return (AVOID_DIST * radius - dist) / radius;
         }

AVOID DIST is simply a constant that corresponds to the diff check from before. (in that example it'd be 2, though 3 gives me a linearly interpolated "extra radius" to adjust.)

I'll keep an eye out for if someone posts a better answer, or I'll accept this one in a week as a work around. I believe the correct answer is located in Boids knowledge however.

alt text


better.gif (485.3 kB)
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

122 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 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 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 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 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

Instantiating A* PF target for RTS 1 Answer

Moving multiple AI units as one for RTS game. 1 Answer

Unit local avoidance in RTS type games 3 Answers

Why does the Unity Navmesh Agent slow down while traversing obstacles? 2 Answers

How to call a method once inside fixed update 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