Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Jer_J · Jul 15, 2015 at 08:45 PM · arraytilemaptileefficiencymultidimensional array

Efficient method of storing coordinate values sequentially in an array

This might be difficult to explain haha, I'll try my best: My game is grid-based and naturally I need a way of storing all possible coordinates and tile properties (walkable, type, coordinates etc). My current idea is to create a C# class, let's say TileIdentify which stores it's position, type, etc. I was hoping to use a multi-dimensional array like so:

TileIdentify[x][z][y] - which should allow me to make calculations at x,y and z. If I wanted to attack characters at adjacent tiles and whatnot.

So here's the problem:

I have a script (used prior to game start) which obtains x,y,z coordinates of a blender model in order to figure out which part of the map a character can access and creates a TileIdentify object for each 1x1 area. It does this through Editor input of max x/z lengths and it figures out the elevations using RayCasts. The issue is that I want to be able to use this code on multiple maps and they will have varying (x,y,z) values. So these scenarios might arise leading to issues in identifying tiles:

TileIdentify[0][0][3], let's say a pillar at (x = 0, z = 0) of height 3 is here but

TileIdentify[0][0][2] won't exist since it's not a walkable surface (part of pillar structure) and thus does not have a tile.

or

TileIdentify[2][1][0] exists but both TileIdentify[0 and 1][1][0] does not (could be a cliff with empty space beside it)

My Questions: Can I still use arrays to identify tiles at specific coordinates, if so, how?

Can I just create a NaN array of TileIdentify[maxX][maxZ][maxY] and just fill in the values that I need - will this impact efficiency since I might potentially create scores of TileIdentify objects?

Other there other better methods I should look into?

Thanks in advance, let me know if you want to see how my code looks for a better idea or if clarity is needed!

Comment
Add comment · Show 3
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 meat5000 ♦ · Jul 15, 2015 at 03:26 PM 0
Share

I kinda glanced over what you wrote. Two words:

Struct

List

avatar image Jer_J · Jul 15, 2015 at 05:03 PM 0
Share

Sorry if sound naive, I just started C# recently (co$$anonymous$$g from beginner level Java and $$anonymous$$ATLAB) but how can I implement structs and lists to perform this task? I can't use Lists within Struct since I will need to initialize everything within the Struct since it is immutable and can't reference anything. $$anonymous$$y second thought is using List(Struct) but how is that any different from List(Object) and how will it enable me to perform calculations along three dimensions since List indexes along a single dimension?

Am I looking at this problem the wrong way?

avatar image Owen-Reynolds · Jul 15, 2015 at 09:01 PM 0
Share

This is a somewhat hard data structures problem. 2nd-year Computer Science students study it. The easy answer is: if an array works, why not keep using it?

If you have few "blanks," most people make the entire array, and use -999 for the blanks.

If you have lots of blanks (70%?) often called a "sparse" array, most people try to make a searchable list of just the active items, with a clever look-up. Each item in the list now needs the coords stored with it.

A single sorted list with a binary search works, or a sorted list for each row. Some people might suggest a Dictionary with a clever key... .

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

2D/Orthographic Tile Alignment Issue 0 Answers

optimizing game objects - deciding what way to organize my level. 0 Answers

How can I access to a tile properties in a Tilemap? 0 Answers

How do you draw from tilepallet to tilemap while the game is running? 0 Answers

Changing tile collider shape 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