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 Ozale · Jun 30, 2011 at 05:28 AM · movementgridboardgame

Building a Chessboard

G'day guys.

I'm beginning a Turn-Based project, where 'units' will move on a grid, similar to Chess. I understand the importance of the basic grid system being as efficient as possible, and I've been trying different techniques. I've thought a multidimensional array populated with 'cubes', each being one 'square' on the 'playing board', would be very useful, but I'm not sure how efficient it is.

I've already built a basic 'State Engine', 'Strategy Camera' and Selection system, but the core of a Turn Based Strategy is the playing field.

I'd love to hear people's suggestions for the 'best-practice' way to go about this.

Cheers,

EDIT: To be more specific:

I'm trying to build the system for movement - when a unit is 'selected', the game keeps track of where he is and examines the 'cubes' around him, seeing if they are empty and moving the unit to their x and z positions if within range, etc. A multidimensional array of cubes mirroring a multidimensional array that uses Intergers to mark 'squares' as occupied or vacant is the only approach that occurs to me. I am hoping to find out if there is a better system, perhaps using only 1 multidimensional array for both the cubes and the 'units' positioned above (or 'on top of') them, maybe replacing the cube gameobject in the array for their corresponding row/column.

Comment
Add comment · Show 1
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 Ozale · Jun 30, 2011 at 05:30 AM 0
Share

Just to clarify, I'm not actually making chess. $$anonymous$$y eventual goal is something akin to tabletop warga$$anonymous$$g, albeit much simpler. I'm aware of existing Chess projects, and unfortunately the systems they use aren't useful here.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by testure · Jun 30, 2011 at 06:15 AM

I'm not quite sure what you mean by 'efficient' in this case, because we're talking about hypothetical cubes. that's 12 triangles per grid space if you're keeping the bottom. Even if your grid was insanely large, it would take a lot of tiles to even come close to pushing the limits of a modern PC or even smartphone. Your real performance gains are going to come from combining static meshes and materials to reduce draw calls.

Other than the specific question about efficiency, I don't really see what you're asking for here. Best practices for what? Building an entire strategy game? something more specific?

Comment
Add comment · Show 1 · 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 Ozale · Jun 30, 2011 at 06:22 AM 0
Share

You're right, I should have been more specific. I'll edit when I get a chance. I'm trying to build the system for movement - when a unit is 'selected', the game keeps track of where he is and exa$$anonymous$$es the 'cubes' around him, seeing if they are empty and moving the unit to their x and z positions if within range, etc. A multidimensional array of cubes mirroring a multidimensional array that uses Intergers to mark 'squares' as occupied or vacant is the only approach that occurs to me. I am hoping to find out if there is a better system, perhaps using only 1 multidimensional array for both the cubes and the 'units' positioned above (or 'on top of') them, maybe replacing the cube gameobject in the array for their corresponding row/column.

avatar image
0

Answer by aJackson · Jun 30, 2011 at 06:51 AM

I'm working on something similar as well. I made an empty game object, attached a box collider to it, then scaled that collider to make a very thin cube. Then I attached a script to it and made it a prefab (this acts as a tile use can use to lay out the grid), the script handles the grid snapping when placing units.

To place units just use OnMouseOver(), OnMouseExit(), and OnMouseDown() to figure out which tile your over (make sure anything between the mouse and tile is set to the "ignore Ray Cast" layer) and reference that tiles transform to position the new unit.

     // for example, this would go on the tile to handle snapping for initial placement:
     // you need to have a reference of the unit being placed
 void OnMouseOver()
 {
     if (tileIsPasable)
     {
         Unit.GetComponent<unitScript>().snapping = true;
         Unit.transform.position = this.transform.position;
     }
 }
 void OnMouseExit()
 {
     if (tileIsPasable)
     {
         Unit.GetComponent<unitScript>().snapping = false;
     }
 }
 void OnMouseDown()
 {
     if (tileIsPasable)
     {
         Unit.GetComponent<unitScript>().snapping = true;
         Unit.transform.position = this.transform.position;
         Unit.GetComponent<unitScript>().state = UnitScript.State.idle;  
     }
 }

 // then this bit would be on the unit, 
 //it attaches the unit to the mouse when it is not being snapped to he grid
 if(snapping == false){
     Vector3 screenPos = Input.mousePosition;
     screenPos.z = 40f;
     Vector3 worldPos = Camera.mainCamera.ScreenToWorldPoint(screenPos);
     transform.position = worldPos;
 }


To move the unit just use the target location's tile transform to figure out the direction and distance and use lerp or something and a transition to move the unit to the desired location.

Not sure if that's what you needed but hopefully it helps.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a 2D Movement Grid 0 Answers

I need help with some grid calculation for a digital board game. 0 Answers

Touch and Drag 3D Objects on a Grid (for Android) 0 Answers

Checker Board Grid 0 Answers

How to Restrict Movement of a Dragged Object to a Game Board? 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