• 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 Xatoku · Mar 12, 2011 at 04:34 AM · movementaibasic

Very Basic Raycasting

Hey guys. I have an extremely basic AI setup where enemies run over to the Player and attack $$anonymous$$m. T$$anonymous$$s kind of works, but it's unrealistic. I need somebody to explain to me a very basic way of having the enemies go around one another in order to get to the Player, as oppose to just running at $$anonymous$$m and pus$$anonymous$$ng $$anonymous$$m away. Could somebody actually just tell me how I should approach t$$anonymous$$s rather than directing me to a premade tutorial? Also, I don't want any of those fancy AI systems like Angry Ant's, just somet$$anonymous$$ng to have the enemies walk around each other. Any ideas?

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 flaviusxvii · Mar 12, 2011 at 05:10 AM 0
Share

Why load your question with "Raycasting"? You're asking about pathfinding. It's actually a fairly demanding thing to do well (not have the characters walk around like total idiots).

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by by0log1c · Mar 12, 2011 at 05:23 AM

Well for a simple local collision detection I guess it could go like t$$anonymous$$s:

  • Face target position(waypoint?)
  • Move forward
  • Raycast a few units forward every (x) time.
  • if collision:

  • Rotate (v) degrees
  • Launch timer of (t) time.
  • Move forward(modified direction).
  • On timer end, face initial target position and resume walk.

Instead of rotating (v) degrees, you could also set a temporary waypoint.

Of course that's a very simplistic concept and you can enhance it as much as you like. For example:

  • If collider in front is dynamic(can move). Maybe you could 'slow down' instead to allow it to clear the area then resume.
  • Once the front raycast $$anonymous$$t. You could launch a series of raycast at various angle to determine the 'shortest escape route' and rotate/set waypoint accordingly.

OR cheat and just add another, bigger, collider, if(rarely) applicable. That's what I can t$$anonymous$$nk of right now. I'm curious as to what solutions other users have.

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
avatar image
1

Answer by Owen-Reynolds · Mar 12, 2011 at 05:35 AM

What I've done with decent results is to have OnCollision between enemies make them sidestep left or right (away from the other guy) for a few frames, then resume tracking the player. What happens is when 6 of them rush you from one direction, they jostle each other into a circle around you, or a line if they are still coming at you.

My code for "is t$$anonymous$$s guy left or right of me" is based on distance from a line (the line the way the enemy is facing.) If you want fancier, you can have a short raycast for a pre-emptive side-step. But, those tend to look a little jerky, like you are bouncing off an invisible wall.

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 Xatoku · Mar 12, 2011 at 11:58 AM 0
Share

So when an enemy touches another, have them move on the X axis a bit and sidestep?

avatar image Owen-Reynolds · Mar 12, 2011 at 05:37 PM 0
Share

Yep. Something like: slideFrames=6; if(myFriend is left of me) slideDir=transform.right; else slideDir=transform.left`. Then in Update: if(slideFrames>0) { slideFrames--; pos+=slideDir;} else normal forwards move. When you hit a pal, he slides right and you slide left.

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

No one has followed this question yet.

Related Questions

Basic AI Movement C# 3 Answers

Enemy strafing AI Top Down 0 Answers

Adjust custom PlayerControls to be used by enemies 1 Answer

Do something every each multiple of 1000.. 2 Answers

2D Random AI 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