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 4illeen · Oct 06, 2011 at 05:54 PM · movement2d arrayhex

Hex map movement problem

I'm working on a HoMM3 clone. I've got a hex map in form of a 2D array GameObject[,] hex = new GameObject[11,15] - 11 rows, 15 columns. Each hex has a script called Data attached to it which holds all it's variables such as:

int y - row number

int x - column numer

bool obstacle - true if there is a terrain obstacle on that field

bool unit - true if any other unit stands on that field

bool canMove - true if active unit can move on that field

Each unit has a variable int speed which is unit's movement speed in hexes. The problem is that units should not walk through other units and/or terrain obstacles, therefore they need to take longer paths. Pic related

alt text

Bear with the yellow highlight is the active monster, it has speed of 6 (as seen on his left side), but due to obstacles and units in north-east direction, he can't go everywhere where he normally could, as he must take the longer route.

I need this script to change canMove variable of each Hex to true if active unit can move there.

More info:

  • The map is made of 3D gameobjects seen from above with Orthographic camera.

  • Each unit is an empty GameObject with it's transform.position equal to transform.position of some Hex. It has a Plane child with the unit graphic.

  • I'm a C# man

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 Sammual12 · Oct 24, 2011 at 08:10 PM 0
Share

Unless I am missing something you are already calculating all the hexes your unit can move to (The dark shaded ones). Can't you just set your flag when you shade the hex?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by BerggreenDK · Oct 06, 2011 at 07:37 PM

cool enought, but I think you might be more/better help from a GameDeveloper forum such as: http://gamedev.stackexchange.com/

Because your problem seems to me, more of a HEX-tile question than an actual Unity problem.

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 SilverTabby · Oct 06, 2011 at 09:34 PM

Hex tile movement is actually really simple:

if you are using a 2-d array to represent your tiles, and you are at tile position X,Y:

  • For square movement, just allow movement to (X+1,Y), (X-1,Y), (X,Y-1), (X,Y+1)

  • For hex movement just allow square movement and add: (X+1,Y+1), (X+1,Y-1)

To visualize why this works, simply shift every other row in a square grid half a space to the right (sorry I don't have a picture off-hand)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Save a precalculated grid path into a jagged 2d array ready to be loaded when need 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Adding elements to a 2d array. 2 Answers

How do I make my character stop falling when you press a button? 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