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 kidl33t · Apr 23, 2013 at 09:14 PM · cubebind

How to bind primative shapes together programmatically?

In my game I have a large cube that represents the player. It can bump into smaller cubes or spawn smaller cubes that are supposed to 'stick' to it. That is, they move in the X and Y axis and rotate by the same amount as the player cube. Sort of like this, if the cubes were touching and attached.

alt text

So for example, it might have a small cube half the size of the big cube, stuck to its left side. As the player cube rotates or moves the small cube should stay there.

I am pretty new to Unity, but I looked at combining the meshes, but I need access to the hit data for each piece separately so that won't work.

Is there a simple way to do this, without keep a list of all things the player has stuck to him and moving them all separately? Even a link to something relevant would be greatly appreciated, since I am new enough that I don't even know what to google. Thanks in advance!

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
2
Best Answer

Answer by AlucardJay · Apr 23, 2013 at 09:25 PM

make the new cube a child of the old cube it is supposed to be attached to :

 newCube.transform.parent = oldCube.transform;

Here is an example script. Create a new scene, create a cube, attach this script, then hit play. After 3 seconds, another cube is created, and then parented to the main cube :

 #pragma strict
 
 private var mainCube : Transform;
 
 function Start() 
 {
     mainCube = transform;
     
     Invoke( "AttachNewCube", 3.0 );
 }
 
 function Update() 
 {
     mainCube.Rotate( Vector3.up * 5.0 * Time.deltaTime );
 }
 
 function AttachNewCube() 
 {
     // this is just creating a new cube
     var cube : GameObject = GameObject.CreatePrimitive( PrimitiveType.Cube );
     var newCube : Transform = cube.transform;
     newCube.position = mainCube.position + mainCube.forward;
     newCube.rotation = mainCube.rotation;
     
     // Here is where the new cube is being parented to the main cube
     newCube.parent = mainCube;
 }
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 kidl33t · Apr 23, 2013 at 09:36 PM 0
Share

Wow, thank you very much! That's absolutely perfect!

I knew I was missing out on something simple but fundamental like that!

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

12 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

Related Questions

Spawning won't work 1 Answer

Unity 3D C# - Gameobject Minecraft Like Placing 0 Answers

Looking for CheckCube 1 Answer

Using Gizmos.DrawWireCube to draw position bounds? 1 Answer

how do I add text to a 3D cube? 2 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