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 SirBedlam · Sep 13, 2012 at 10:26 PM · aienemypathfindingobstacle avoidance

Obstacle avoidance not working

First of all, I've already tried every free obstacle avoidance and pathfinding tool there is. Yes, every single one. NONE of them work for me. Except for Path, which I never even downloaded due to the sheer number of reviews informing others that it completely ruins your scene and forces you to rebuild from scratch. I've also tried EVERY SINGLE obstacle avoidance and pathfinding script I could find after searching 2 days for a solution. There is simply no script on the entire internet that will work for me. I've searched google, believe me, going so far that the search results don't even have anything to do with Unity anymore. Still, no luck. I hope you can understand my practically painful frustration. First, I'll start with one of the countless number of scripts that I've already tried.

 var target : Transform;
 var repelForce : int = 20; // The force of which the object is pushed
 var walkSpeed : float = 1;
  
  
 function Update(){
 var dir = (target.position - transform.position).normalized;
 var hit : RaycastHit;
 var leftRay = transform.position;
 var rightRay = transform.position;
 leftRay.x -= 2;
 rightRay.x += 2;
  
 if(Physics.Raycast(transform.position, transform.forward, hit, 20)){
      if(hit.transform != transform){
          Debug.DrawLine(transform.position, hit.point, Color.red);
           dir += hit.normal * repelForce;
      }
 }
  
 if(Physics.Raycast(leftRay, transform.forward, hit, 20)){
      if(hit.transform != transform){
           Debug.DrawLine(leftRay, hit.point, Color.red);
           dir += hit.normal * repelForce;
      }
 }
  
 if(Physics.Raycast(rightRay, transform.forward, hit, 20)){
      if(hit.transform != transform){
           Debug.DrawLine(rightRay, hit.point, Color.red);
           dir += hit.normal * repelForce;
      }
 }
  
 var rot = Quaternion.LookRotation(dir);
 transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime);
 transform.position += transform.forward * walkSpeed * Time.deltaTime;
  
 }

What's going wrong? Well, everything. My enemy isn't even going after the player. It's running off into other parts of the level, while twitching like crazy and leaning about 45 degrees to the right...? After a minute of wandering, it starts going in circles, then starts going through walls. Not to mention the fact that it's floating about 3 feet off the ground the entire time. That is until it decides to fly diagonally up into space. So I guess what I'm asking is if there are any other working object avoidance scripts I could try. I should also mention that I'm NOT using a flat level with simple primitives here and there. I'm using a very large and complex building with multiple levels. So box, sphere and capsule colliders will not work for me, unless I want to spend 5 days covering every single wall and stairway with them. I've tried different scripts that would have worked, if my building was using box colliders instead of mesh colliders. I don't know if raycasts just don't work with mesh colliders or what, but my enemy doesn't even detect them, and goes right through them. I am extremely frustrated, and about to give up all together, but I'm clinging onto the one hope that someone here might be able to help.

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 SirBedlam · Sep 14, 2012 at 01:19 AM 0
Share

Can someone please help me? I really need to figure out a way to do this.

0 Replies

· Add your reply
  • Sort: 

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enemy units behave normally, until they rotate, then their AI seems to break 0 Answers

Horde of NavMeshAgents - stops to recalculate path. 4 Answers

How to I make FindGameObjectWithTag() not just find itself? 1 Answer

Object Avoidance for my enemies 1 Answer

Looping Between Waypoints 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