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 DrKillinger · May 05, 2014 at 08:10 PM · movementtileturn-basedmaps

Tile-based maps & movement - linking tiles?

Hi all

I am working on a tile-based, turn-based game in Unity2D, with random maps. I've gotten to a point where I have a random maps, and the correct unit movement behavior, but my method of moving between tiles is proving cumbersome.

Basically, each tile is a GameObject with a sprite and a script. The script describes the tile (primarily, if it can be walked across- "walkable"), and each tile is linked to it's 8 neighbours in an Array, indexed clockwise from 12 o clock (making 0 up, 2 right, 4 down, 6 left, and odd numbers being diagonal neighbours).

THere is the movement code for my unit, where he checks if he can move into the block, and if he can, he moves:

 public bool MoveUp(){
         tile destination = currentTile.neighbours[0];
         if(destination.walkable == true)
         {
             pos += Vector3.up;
             return true;
         } else {
             return false;
         }
     }


Now, this is proving to be a heck of a lot of work when randomly generating maps, and trying to get all the neighbours indexed with their neighbours is a lot of work. I would love to not have to do that, and rather check for neighbours, walkability, etc, on the fly, but I'm not sure how to approach this? Is there a way to arbitrarily check if there is a tile to the north of my current tile, for example?

If I should be linking each tile to all it's neighbours, is there ane xisting algorithm for terrain generation I can have a look at?

Thanks in advance.

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
0

Answer by Oniromancer · May 24, 2014 at 01:40 PM

Hi. This is my first answer ever, so take it with caution. First: checking "walkability" on the fly should be a matter of getting the script component on the target tile, and having the properties you need to read as public. Then again, I think is always good practice to have a matrix-like structure that represents the map AND that each tile knows who the neighbors are. This allows you to implement pathfinding algorithms like A* (and many others). I usually implement and algorithm in the start phase of my map representation, but I guess this can prove to be inefficient if the map is too big and you are randomly generating. (Maybe in that case you can implement the neighbor assignment during the generation phase, so you don't have to go twice over the whole matrix)

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

21 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

Related Questions

Charecter Controller like in Merry Bear game(Cube based game). 0 Answers

How to make sprite move behind part of tile 1 Answer

How i can allowed a game object to have only one move on each turn?, 0 Answers

Move character to specific tiles on map. 1 Answer

Movement outline 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