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 ThisIsMarkS · Jul 14, 2013 at 01:33 AM · aienemyfollowstopturn

AI enemy Stuck at corners

I have an AI script for my enemy which has character controller: Its aim is to follow the player and It actually does But when the ai meets certa![alt text][1]in situations like what is on the attached picture: [1]: /storage/temp/13119-untitled-1.jpg It gets stucked! My question is : How can i make the enemy "stop following the player and turn" then "after turning follow the enemy"? Please help!

untitled-1.jpg (34.4 kB)
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 fafase · Jul 21, 2013 at 10:30 PM 0
Share

I tend to narrow down the actions on my algorithms. In your case it would go:

  1. Check the distance

  2. Check the line of sight

  3. Check the linecast

Now if all of those go true it means the NPC is close enough, the player is front and the NPC can see the player. It still can happen that an obstacle is in between so you check the raycast.

See doing this way, you can avoid some useless action like your Linecast at the beginning.

As for rotating you only need to apply a rotation by a defined angle if the raycast hits something, if the raycast keeps on hitting then your guy will rotate until free.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DryTear · Jul 14, 2013 at 02:08 AM

A* Pathfinding is what you need : LINK

The current script your using directly follows the target no matter what, pathfinding consists of way points that allow the enemy to move by the way points to its target.

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 ThisIsMarkS · Jul 16, 2013 at 01:56 PM 0
Share

I've made a solution using Linecast... Anyway, thank you for your response! I'll try to read it and compare which solution is better.

avatar image
0

Answer by fafase · Jul 16, 2013 at 02:03 PM

If you don't want to go into pathfinding - which is the ultimate way anyway - you can use steering behaviours.

While your guy is heading to the player, you have two raycasts on each side of the NPC and if the cast returns true, you have a hit, rotate the NPC by an angle.

It is just a basic solution that will not fix entirely the issue and there could be (will be) situations where your guy is just stuck.

But it is an easy way.

Comment
Add comment · Show 2 · 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 ThisIsMarkS · Jul 16, 2013 at 02:36 PM 0
Share

You cant blame me because I'm just a student, and i find it hard to understand the script in pathfinding... so I just solved it my own way... Actually I have 3 linecast including in front of the enemy: -The enemy keeps moving forward -rotating towards the player -if the enemy hit something in front it will rotate either left or right ins$$anonymous$$d of rotating towards the player until the cast in forward disappeared -if the cast in forward disappeared it will continue ai$$anonymous$$g towards the player Can you help me shorten my code?

avatar image DryTear · Jul 17, 2013 at 12:30 AM 0
Share

show the code, we fix it and we will explain it to 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

16 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

Related Questions

Enemy Pathing 1 Answer

How to make an AI like slender ? 1 Answer

AI Following Problem 1 Answer

How can I ground enemies and use target transform? 1 Answer

How do I make it so that a walking animation plays for the enemy AT THE SAME TIME it is moving toward the player? 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