Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
2
Question by Descalium · Feb 05, 2019 at 10:10 PM · programmingtilemaptilesisometric

How do you get the tile on which a gameObject is standing on Isometric Tilemap ?

Hi everybody !

I'm trying to use the isometric z as y tilemap and create a character on it. I want that the character can snap on the grid case exactly like the tile. But... It work in a way that i can't understand.

alt text

alt text

Why do they have different position ? How can i get the tile (and it position) on the gameObject is ? I'm so confuse right now.

Can someone (maybe) explain me, how do we create a lambda character and make it move on the grid ? (with taking the tile's position where he is standing on ?)

Thank you for reading,

grid.png (174.4 kB)
character.png (196.2 kB)
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
5
Best Answer

Answer by z_orochii · Feb 06, 2019 at 06:20 AM

If you know the exact grid position (the one that shows at the first screen you posted), you can use GridLayout.CellToWorld to, as the method name suggests, convert a cell position into a world position. This one receives a Vector3Int with the position relative to the grid.


In order to use CellToWorld you must have a reference to the Grid object (like the one tilemaps use). And if you want to know the current (closest) cell where an object in the world is, you can use the opposite method: GridLayout.WorldToCell. This one receives as parameter a Vector3 corresponding to a point in the world space.


Hope it helps!

Comment
Add comment · Show 5 · 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 Descalium · Feb 06, 2019 at 10:50 AM 1
Share

Thank you very much. Actually, it work perfectly with this kind of code :

 Vector3Int lPos = grid.WorldToCell(player.transform.position);
             Debug.Log("name : " + tilemap.GetTile(lPos).name + " & position : " + lPos);



avatar image AllanHouse Descalium · May 03 at 11:03 AM 0
Share

Any way to bump up this solution? It's perfect, easy to implement, easy to understand, complete and works. But it is VERY hard to find this info through google.

avatar image CoolTube_YT1234 · Sep 08, 2021 at 10:59 AM 0
Share

Is there a way to sense if a tile is empty? If I do the method you provided whenever I move my character to an empty tile it gives me an error.

avatar image z_orochii CoolTube_YT1234 · Sep 08, 2021 at 03:07 PM 0
Share

If you're using Descalium's code, just add a check for when the result from GetTile gives you null before asking for the tile name.

WorldToCell and/or CellToWorld shouldn't give you any issue with empty tiles, as it's just a conversion from world to grid. It doesn't use tiles or even the tilemap at any point.

avatar image CoolTube_YT1234 z_orochii · Sep 08, 2021 at 06:26 PM 0
Share

@z_orochii Yea the problem is that its not giving me null, its giving me an error. I tried checking for null but that didn't work. I'm pretty new to Unity so I don't know how to do this. Also is there a way to check for the name of an adjacent tile? Edit: I'm also having trouble using the tile name in if statements. if (TileMap.GetTile(lPos).name == Grass) { // script here }

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

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

Multiple Cars not working 1 Answer

How to get adjcent tiles (horizontal or vertical) in an isometric tilemap ? 1 Answer

Isometric grid snapping 0 Answers

Interact with tile / triggering script 1 Answer

How to count Tiles in a sourinding Area around an Object? 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