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 Flytex · May 17, 2013 at 12:32 AM · ainavigationmaze

Maze navigation

Hey this script is meant to navigate an enemy yhrough a maze to the character it works outside the maze but when i put them inside nothing happens. Can anyone help??

   function Update(){
      var target = GameObject.FindWithTag("Player");
 var right = transform.TransformDirection(Vector3.right);
 var left = transform.TransformDirection(Vector3.left);
 var fwd = transform.TransformDirection(Vector3.forward);
  if (!Physics.Raycast(transform.position, fwd, 20) & !Physics.Raycast(transform.position, right, 40) & !Physics.Raycast(transform.position, left, 40)){
 transform.Translate(Vector3.zero);
 transform.LookAt(target.transform.position);
 transform.Translate(Vector3.forward * 15 * Time.deltaTime);
 }
 else if (!Physics.Raycast(transform.position, fwd, 20)) {
 transform.Translate(Vector3.zero);
 transform.Translate(Vector3.forward * 15 * Time.deltaTime);
 }
 else if (!Physics.Raycast(transform.position, right, 40)) {
 transform.Translate(Vector3.zero);
 transform.Rotate(0,25,0);
 }
 else if (!Physics.Raycast(transform.position, left, 40)) {
 transform.Translate(Vector3.zero);
 transform.Rotate(0,25,0);
 }
 }
 
Comment
Add comment · Show 5
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 rutter · May 17, 2013 at 12:55 AM 0
Share

Are the raycasts hitting anything? You might add some Debug.Log() calls to follow the program's execution, or use $$anonymous$$onoDevelop's built in debugger to step through the code as it runs.

avatar image Flytex · May 17, 2013 at 07:47 AM 0
Share

I'll have a look but it works outside of the maze so that's what confuses me

avatar image whydoidoit · May 17, 2013 at 07:57 AM 1
Share

Well a maze is a pretty tight environment so it could just get stuck I'd guess, especially if it wasn't perfectly rotated in the sense of the maze, all of those ray casts could hit causing it to do nothing.

avatar image Flytex · May 17, 2013 at 10:55 AM 0
Share

so could i fix that in any way or do i have to use a new statement??

avatar image Bunny83 · May 17, 2013 at 11:53 AM 0
Share

Yes the fix can be compared to "how to fix my paper-airplane so i can fly with it over the ocean". The answer is: "build a real airplane".

All you have there is a very (very) simple collision avoidance system which is far from being a navigation logic. For navigating a maze you need something like a pathfinding algorithm (A* for example which is the most common and simplest one). There is no easy "fix" for your problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TonyLi · May 17, 2013 at 03:19 PM

http://u3d.as/content/angry-ant/path/1zq

Asset Store description:

Path By AngryAnt, Free: The Path project is an easy to use, powerful, waypoint based pathfinding solution for Unity.

Its primary goal is to allow the user to quickly and easily add pathfinding to a scene and immediately take advantage of it through a super simple API. At the same time, the before mentioned API also holds powerful accessors for runtime throttling of the co-routine based seekers, custom weights, path recalculation and more.

Documentation is available at http://angryant.com/path

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

17 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

Related Questions

Any recommendations for having randomized obstacles for a nav mesh? 1 Answer

Ai Upgrade?? Possible 1 Answer

NavMeshAgent not moving 0 Answers

Ai Zombie Melee Attack script. 5 Answers

Enemy following Player on uneven surface 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