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
0
Question by Dougtay · Nov 21, 2019 at 01:17 PM · 2d2d gametilemapgridgrid based game

How can i make the Unity2d grid use rounded numbers?

I'm new to unity and am creating a simple grid-based game to understand things better. in the game I have a "start position" tile that sets where my hero will start the level. however, I can't seem to get the tile to be located at a clean (1,2) kind of coordinate. instead, the location of the tile is always a long float out to several decimal places, like (-3.897622, 0.9561565). This is creating problems further down the road when I want to specific particular cell/tile locations. Is there a way to force unity to use Ints or rounded floats for its grid locations?

Comment
Add comment · Show 11
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 Hellium · Nov 21, 2019 at 01:29 PM 0
Share

How do you place the tiles? By hand in the editor? If so, you can change the "Edit > Snap Settings" and hold CTRL key (or C$$anonymous$$D on $$anonymous$$ac) when moving your tiles.

avatar image Dougtay · Nov 21, 2019 at 06:17 PM 0
Share

thanks. yeah, i'm snapping to the grid that way and I've set the snap settings to whole values for x/y/z. The tiles still snap to odd values. maybe I've hit a bug...

avatar image Hellium Dougtay · Nov 21, 2019 at 07:25 PM 0
Share

The Snap settings is in fact a "step" setting. Set the position of the tile to a round value (like 0, 0, 0), and when you hold CTRL key, the tile will be moved by 1 unit. If the initial position of the tile is something like 1.89756, 6.578996, 0.345663, moving the object while holding CTRL will just move the tile by 1 unit 2.89756, 6.578996, 0.345663

avatar image Dougtay Hellium · Nov 21, 2019 at 07:36 PM 0
Share

gotcha thanks. This suggests that if i'm building off a grid, then the first tile/object I place in the seem is effectively how the grid is defined thereafter. is that right?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by astrospacemoth · Nov 21, 2019 at 05:58 PM

I'm going to assume your tiles are NOT placed by hand in the editor, but rather at runtime. There is Mathf.Round which might work in this case. Try running your location value through that. https://docs.unity3d.com/ScriptReference/Mathf.Round.html

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 Dougtay · Nov 21, 2019 at 06:24 PM 0
Share

i'm placing them in the editor using grid snap no at runtime. things should just always snap to rounded values by default right? $$anonymous$$y grid anchors are all set to zero, grid settings for snap are all set to 1, etc.

avatar image astrospacemoth Dougtay · Nov 21, 2019 at 06:28 PM 1
Share

Try holding Ctrl while moving the object in the editor.

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

253 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 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 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 stack components on a Tile/Tilemap 0 Answers

Tilemap disappearing from game-view after using SetActive 1 Answer

2D Light question 1 Answer

Tilemap Grid Broken? 1 Answer

2D Tile Map Question 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