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 /
  • Help Room /
avatar image
0
Question by SharpCoder · Apr 11, 2016 at 03:04 PM · c#positioncubestick

Aligning sticky cubes

Hi!

I am trying to realize a Lego-like constructor. It will work with cubes with different materials. I made a prefab for a cube with this script: using UnityEngine; using System.Collections;

 [RequireComponent(typeof(BoxCollider))]
 [RequireComponent(typeof(Rigidbody))]
 public class StickScript : MonoBehaviour
 {
     private Rigidbody myRigid;    
     public void Start()
     {
 
         myRigid = gameObject.GetComponent<Rigidbody>();
     }
 
     public void OnCollisionEnter(Collision collision)
     {
         // all sticky objects have this tag
         if (collision.gameObject.tag != "Sticky")
             return;
 
         
         // if we are not connected to other object
         foreach (FixedJoint fj in collision.gameObject.GetComponents<FixedJoint>())
         {
             if (fj.connectedBody == myRigid)
                 return;
         }
 
         var otherRigid = collision.gameObject.GetComponent<Rigidbody>();
         
         // if we didn't connected other object
         foreach (FixedJoint fj in gameObject.GetComponents<FixedJoint>())
         {
             if (fj.connectedBody == otherRigid)
                 return;
         }
 
         // Connecting
 
         collision.gameObject.transform.rotation = gameObject.transform.rotation;  // rotating
         var joint = gameObject.AddComponent<FixedJoint>();
         joint.connectedBody = collision.rigidbody;
 
 
     }
 }

I am rotating the cubes, so they aligned properly... But i didn't understand how to make cubes to stick aligned: cubes must be connected by edges. Without this, I am getting this: alt text

Can you help me with the position transformation when sticking?

With best regards

P. S. The mechanism of connecting: I am moving this blocks by using Leap Motion - they are rigidbodies, so I can move them by hands

bug1.png (16.5 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Redwolve · Apr 12, 2016 at 03:22 AM

What exactly is the mechanism for deciding what to connect? Are you dragging and object or moving an object into another? Trying to understand what brings them to each other and the state they are in when you try to "stick" them

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 SharpCoder · Apr 12, 2016 at 07:13 AM 0
Share

The mechanism of connecting: I am moving this blocks by using Leap $$anonymous$$otion - they are rigidbodies, so I can move them by hands

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

Raycast positioning problem 1 Answer

error CS1061: Type `UnityEngine.LineRenderer' does not contain a definition for `numPositions' and no extension method `numPositions' of type `UnityEngine.LineRenderer' could be found 1 Answer

How to make a cylinder that dynamically connects two objects? 0 Answers

Instantiate prefab if no prefab exists at location 1 Answer

Resetting Camera Position 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