Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Flipnoter · May 26, 2014 at 06:37 PM · buildingminecraft

Trouble with Minecraft like building

How would I go about creating a way to build things in a game in a way that is similar to Minecraft but allows for non-cube block dimensions.

I currently have a partially working method but in some instances the object will be not align to an already existing object.

Here is an example.

alt text

Here is my current code.

 Vector3 TempInstScale = TempInst.transform.localScale;
 
         if(Input.GetKeyDown(KeyCode.Keypad8)) {
 
             TempInstScale.x += 0.2f;
 
         }
 
         if(Input.GetKeyDown(KeyCode.Keypad2) && TempInstScale.x > 0.2f) {
             
             TempInstScale.x -= 0.2f;
                 
         }
 
         if(Input.GetKeyDown(KeyCode.Keypad9)) {
             
             TempInstScale.y += 0.2f;
             
         }
         
         if(Input.GetKeyDown(KeyCode.Keypad3) && TempInstScale.y > 0.2f) {
             
             TempInstScale.y -= 0.2f;
             
         }
 
         if(Input.GetKeyDown(KeyCode.Keypad7)) {
             
             TempInstScale.z += 0.2f;
             
         }
         
         if(Input.GetKeyDown(KeyCode.Keypad1) && TempInstScale.z > 0.2f) {
             
             TempInstScale.z -= 0.2f;
             
         }
 
         if(Input.GetKeyDown(KeyCode.Keypad5)) {
             
             TempInstScale = new Vector3(1, 1, 1);
             
         }
 
         TempInst.transform.localScale = TempInstScale;
 
         TempPlaceObj.transform.localScale = TempInstScale;
 
         float GridSize = 0.2f;
 
         if(HotBar[HotBarSlot].Item_Type == Items.ItemType.Block) {
 
             Ray rayplc = cam.ScreenPointToRay(Input.mousePosition);
             RaycastHit hitplc;
 
             if(Physics.Raycast(rayplc, out hitplc, 50  + GameObject.Find("PlayerCam").GetComponent<CameraControl>().DistanceToTarget)) {
 
                 TempPlaceObj.SetActive(true);
 
                 Vector3 pivotpoint = (hitplc.point + hitplc.normal / 2) - hitplc.transform.position;
 
                 if(hitplc.collider.tag == "Ground") {
 
                     if(TempInstScale.y == 1) {
 
                         pivotpoint.y = 0.5f;
 
                     }
                     else
                     {
 
                         pivotpoint.y = TempInstScale.y / 2;
 
                     }
                 }
 
                 float tileX = pivotpoint.x / GridSize;
                 tileX = Mathf.Round(tileX);
 
                 float tileY = pivotpoint.y / GridSize;
 
                 if(hitplc.collider.tag != "Ground") {
 
                     tileY = Mathf.Round(tileY);
 
                 }
 
                 float tileZ = pivotpoint.z / GridSize;
                 tileZ = Mathf.Round(tileZ);
 
                 float WorldX = hitplc.transform.position.x + tileX * GridSize;
                 float WorldY = hitplc.transform.position.y + tileY * GridSize;
                 float WorldZ = hitplc.transform.position.z + tileZ * GridSize;
 
                 Vector3 WorldPos = new Vector3(WorldX, WorldY, WorldZ);
 
                 TempPlaceObj.transform.position = WorldPos;
 
                 if(Input.GetMouseButtonDown(0)) {
 
                     Instantiate(TempInst, TempPlaceObj.transform.position, new Quaternion(0, 0, 0, 0));
                     
                 }
 
                 if(Input.GetMouseButtonDown(1) && hitplc.collider.tag == "Block") {
                     
                     GameObject.Destroy(hitplc.collider.gameObject);
                     
                 }
             }
             else
             {
 
                 TempPlaceObj.SetActive(false);
 
             }
         }
         else
         {
             
             TempPlaceObj.SetActive(false);
             
         }


screenshot 0 .png (410.2 kB)
Comment
Add comment · Show 2
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 supernat · May 26, 2014 at 06:40 PM 0
Share

There are probably multiple approaches, but it seems like you could enforce that all objects created in the world are in multiples of your grid size, and then snap those objects to the grid. In other words, if the grid is to allow snapping every 5 world units, then objects need to have a width/height that is always a multiple of 5.

avatar image Flipnoter · May 26, 2014 at 07:09 PM 0
Share

Just tried that and it didn't work.

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

21 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

Related Questions

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

Can someone fix this building and breaking code? 0 Answers

Help! Saving blocks in a grid-based building system 0 Answers

MaK like building script help... 0 Answers

Building using raycasts similar to Minecraft 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