Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 monish_97 · Oct 04, 2017 at 11:19 AM · 2dgridgrid based gamepuzzleblock

Block puzzle (1010) help

Hello Friends,

![alt text][1]

Im developing a block puzzle game (replica of this: https://play.google.com/store/apps/details?id=com.differencetenderwhite.skirt&hl=en)

I have a grid of 8X8 cells. I have colliders (Triggers) on each cell. Also there is a collider on the shape (red) which can be dragged in the grid and can be placed inside the grid. Now how can I determine where I should snap the object (on which cells it should be placed?)

Thanks in advanced. -Monish H. Vyas [1]: /storage/temp/103098-capture.png

capture.png (11.5 kB)
Comment
Add comment · Show 5
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 toddisarockstar · Oct 05, 2017 at 05:23 AM 0
Share

first of all i would not use a collider system. i would create an array of arrays in C#. this way you have 2D info to represent info about certain squares on your board. then i would use small reletive coordinates that go with the pieces for checking for a fit. to snap objects you simply use mathf.round against positions. if you need code example for such a system let me know.

avatar image monish_97 · Oct 05, 2017 at 10:10 AM 0
Share

@toddisarockstar Thank you for your valuable feedback. I will try this new approach and will let you know. If things don't work I'll ask your help for a code example.

avatar image monish_97 monish_97 · Oct 09, 2017 at 09:39 AM 0
Share

float ShapeX = $$anonymous$$athf.Clamp($$anonymous$$athf.Round( 2f * transform.position.x) / 2, -GRID_BOUND, GRID_BOUND);

float ShapeY = $$anonymous$$athf.Clamp($$anonymous$$athf.Round( 2f * transform.position.y) / 2, -GRID_BOUND, GRID_BOUND);

Shadow.transform.position = new Vector2(ShapeX, ShapeY);

Shadow is a game object that represents the prospected position of the shape in the grid. The shape will be placed at Shadow.position when Input.Get$$anonymous$$ouseButtonUp(0) is called.

I am rounding the position to snap it so values (0.5, 1.0, 1.5, etc...) and clamoing the whole value to allow dropping the shape only inside the grid.

GRID_BOUND is a float constant calculated based on cell size and number of cells.

avatar image monish_97 · Oct 21, 2017 at 01:23 PM 0
Share

Hello guys, I seem to have solve the issue of deter$$anonymous$$ing the cell is available or not by using an array. Thanks to @toddisarockstar

Now I am using position of each cell of the shape to deter$$anonymous$$e on which cell it will be put in the grid. Now the problem is the values are in floats so I cannot use a switch statement. How can I get cell index in both X and Y directions using transform.position.

P.S. Right now Im using exact values 1.8, 1.3, etc.. But I want to create a formula to avoid using multiple condition checking.

avatar image toddisarockstar monish_97 · Oct 21, 2017 at 10:22 PM 0
Share
         //this will give you 4!!
         $$anonymous$$athf.RoundToInt (3.7f);
 
         //this will give you a 3//
         $$anonymous$$athf.FloorToInt(3.7f);

         // one of these should work to give an intreger!!
 
 
         $$anonymous$$athf.RoundToInt (transform.position.x);
         $$anonymous$$athf.FloorToInt(transform.position.x);

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

134 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

Related Questions

How to detect collision of a wall with grid movement? 1 Answer

How can i make the Unity2d grid use rounded numbers? 1 Answer

!URGENT! How to make a grid of clickable objects. 1 Answer

grid-based block placement system with touch input 1 Answer

Keyboard not working in build (is working in editor) 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