• 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 MousePods · Sep 04, 2012 at 05:43 PM · movementcharactercontrollerangle

Moving in a Arch

I have a enemy that, when the player is within a certain distance, the enemy will move away, trying to escape the player based on the dir ( player.pos - enemy.pos )

Of course, I have the problem of the enemy getting stuck on walls and in corners (in a square room).

My question is, how do i calculate a arch movement that, when the enemy hits a wall, they will move at an angle away from the wall but also curving around the player. I'm hoping that this will fix the problem of getting stuck against walls and corners.

A better way put, possibly

When the enemy hits a wall or some other obstacle, it will look for an escape in a direction at least 90 degrees away from the player's position relative to the enemy.

Thanks!

(I have already tried rays and changing the dir when x or z is 0, it works for corners but not when the character is diagonally to the enemy when the enemy is caught in a corner )

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

1 Reply

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

Answer by Screenhog · Sep 04, 2012 at 07:19 PM

What you want is a pathfinding solution. The way you proposed is okay, but it can lead to further complications... it's usually better to just have an enemy decide on a new place where it should go and then calculate the path to get there.

There are multiple good solutions out there for this. Unity Pro has a pathfinding solution built-in, and Aron Granberg wrote a good one that you can find on the Asset Store.

Comment
Add comment · Show 3 · 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 MousePods · Sep 04, 2012 at 07:51 PM 0
Share

Well, I was trying to avoid that since the other enemies will not be using pathfinding, but thanks for the info!

avatar image Screenhog · Sep 04, 2012 at 09:00 PM 1
Share

Perhaps there's a better way, then. Ins$$anonymous$$d of calculating where it should go when it hits a wall, could you do a raycast in front so that a unit will know in advance that it's about to hit a wall, and can adjust ahead of time?

avatar image MousePods · Sep 04, 2012 at 10:55 PM 0
Share

Yes, iv tried something to that extect and it works, sort of. I raycast in all directions when when I hit a wall, i change the direction accordingly, however, then the enemy still gets caught in the corner if the player is diagonal or straight on when the enemy is not in a corner.

I am horrible at explaining things, but, I changed up the enemies behaviour a bit so that it works with what I have. Thanks for trying tho!! I really appreciate it!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

How can I guarantee a CharacterController never leaves the ground? 2 Answers

CharacterController.Move() is causing unwanted vertical movement . . . how to fix? 2 Answers

FPC Moves itself 0 Answers

Curve player movement 1 Answer

CharacerController not allowing mid-air movement 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