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 /
This question was closed Oct 03, 2011 at 05:07 PM by DavidDebnar for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DavidDebnar · Jul 06, 2011 at 02:14 PM · gridpuzzlestacking

Stacking Lego pieces

Hey guys, Im making a weekend proejct. It will be a puzzle game, based on grid placing blocks. I can place them, but there is a slight problem with stacking. I need to check if the lego piece should or shouldnt go higher -- aka stack like a tower.

Lego.js

 var totalDist : float;
 var actualBlock : Transform;
 var blockIsPlaced : boolean = true;
 var block : Transform; //one lego piece
 var x : float = 0;
 var y : float = 0;
 
 function Update (){   
        CheckForPlacing();
        GetInput();
       
 
 if(!blockIsPlaced){
                actualBlock.position.x = x - 2.5 * totalDist;
                actualBlock.position.y = y - 1.5 * totalDist;}}
 
 function CheckForPlacing () {
  if(blockIsPlaced)
         {            
                actualBlock = Instantiate(block, Vector3(
                                          transform.position.x,
                                          transform.position.y,
                                          transform.position.z - 0.1
                                          ),transform.rotation);
                actualBlock.parent = transform;
                blockIsPlaced = false;}}
 
 function GetInput (){
         if(Input.GetKeyDown(KeyCode.RightArrow)){
                if(x != 5){
                        x += 1;}}  
     if(Input.GetKeyDown(KeyCode.LeftArrow)){
                if(x != 0){
                        x -= 1;}}
       if(Input.GetKeyDown(KeyCode.UpArrow)){
                if(y != 5){
                        y += 1;}}     
      if(Input.GetKeyDown(KeyCode.DownArrow)){
                if(y != 0){
                        y -= 1;}}
      
      if(Input.GetButtonDown("Jump")){
                blockIsPlaced = true;}}
     

  • David

PS: I hope that you will understand. :-)

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 DavidDebnar · Jul 06, 2011 at 03:25 PM 0
Share
  • bump *

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by DavidDebnar · Jul 11, 2011 at 09:31 AM

Ok I have it, just wanna close this thread.

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 aman_jha · Jun 05, 2016 at 01:05 PM 1
Share

How did you do it? I'd like to see for my own project.

avatar image DavidDebnar aman_jha · Jun 05, 2016 at 01:11 PM 0
Share

Hello! I've entirely forgotten about this question. I'll edit my answer in a couple hours with the correct answer and some example code.

The solution I used was to do a Raycast directed away from the camera, to the point where you want the next lego piece to be spawned.

Another solution would be to keep a hashset/dictionary of all the currently spawned lego pieces, where the key is a Tuple/$$anonymous$$eyValueStore. If a value isn't present, it means that position in the world is free.

avatar image
0

Answer by flaviusxvii · Jul 06, 2011 at 04:36 PM

It sounds like you need to keep a list of occupied locations in the world. When you go to place a block you can check over the list to see if the position is occupied and choose the position above (which you'll also have to check to see if it is occupied.)

Get that working and you can look into using a 3D array to optimize it.

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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Check children on a grid 1 Answer

Puzzle piece rotation 0 Answers

Need help finding why my onGUI() sliding image puzzle has errors! 1 Answer

How to let player move for specific number of times in gird base system.,Implement a move system in grid where player can move for specific number then dies if he did not meet game end/ 0 Answers

Grid Based Mouse Drag 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