Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Maskimus · Jul 22, 2017 at 01:54 PM · movementdirectionaxisenemy ai2.5d

Enemy AI Movement one axis at a time (8 directional - 2.5d) towards player/target

I'm having real trouble with this, i have a character which uses .GetAxisRaw to move in 8 directions in a 2.5D environment, see pic:

alt text

The issue is, i don't think there is anyway i can use the same system(GetAxisRaw) for my Enemy AI movement? I have tried various scripts for other methods and they all seem to move the Enemy AI between x,y causing the Enemy to take the shortest distance to the target which looks like he is Iceskating in a 2.5d Environment.

What i need is a way to Lock movement to one axis/direction(of the 8) at a time while moving towards the player/target.

Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tomandresen · Jul 24, 2017 at 08:59 PM

You can take the position of the player as a Vector2 and subtract the position of your enemy, also as a Vector2.

You now have a direction vector towards the player. You can then either do something involving angles (and possibly the cross product between the vectors as Vector3s to determine direction), or you can simply inspect the x and y coordinates of the direction vector and use that to determine which of the 8 direction to move in.

Then, once you have determined that, you then move the enemy in the appropriate direction.

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
0

Answer by Lili-Shi · Jul 22, 2017 at 02:21 PM

I don't exactly know how to program AI-movement, but if you use any commonly used pathfinding systme (i.e. Dijkstra's Algorithm or A*), and a grid-based node-path, why don't set your AI up to only move along one of 8 nodes?

If you have no clue what I am talking about, donot fear. I highly recommend watching this video-series by quill18creates: Civilization/Dungeon Tile Movement & Pathfinding It is very good, and quill18 explain's the system behind that very well.

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 Maskimus · Jul 22, 2017 at 09:01 PM 0
Share

I have looked into A* and other navmesh type AI system's but I'm not really sure a grid system will work for the map sizes i intend to use and i don't really want to splash out $100 to find out it doesn't suit my needs.

The AI i intend to use is really simple, idle, chase once player enters within x range, and that's all there really is to it. Once i can work my movement issue it should be fairly straight forward.

Thanks for the info though.

avatar image Lili-Shi Maskimus · Jul 24, 2017 at 03:55 PM 0
Share

Why spend any money for anything? Again, you can take a look into the video-series I linked, and take a look as to how to program it yourself. In that series quill18 creates a procedurally generated terrain, that consists of cubes (that that really is a grid-based node-system).

Also, I guess a grid-based node-system would be the exact thing to suit your needs, you want the AI to only move along 4 axis (N-S/S-W, W-E/E-W, NE-SW/SW-NE, NW-SE/SE-NW) and a grid would achieve exactly that (as you could set the AI up to move over the vertices and edges).

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

98 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 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 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 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 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 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

How to prevent movement in a specific direction only? -1 Answers

Stop object movement in 1 direction along axis 1 Answer

How to edit Direction Angle using GetAxis 2.5D 8 direction movement 1 Answer

Making a character move automatically in one direction. 2 Answers

bullet problems 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