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
0
Question by BiTimup · Nov 14, 2014 at 09:34 PM · colliderphysics.overlapsphere

Question: how to overlap 2 cubes objects

My problem is that I want to make a static cube object will be overlapped with another cube object. As a result, the cube object will be fit into the static cube object. Note: The static cube object will be bigger than the cube object, and we can see at the end of overlapping, the static cube will be like a frame of the cube object.

What I tried was: Using Sphere Collider on the Cube, so that I only need to use radius of the to sphere to detect the collision.

float distance;

//position of the letter object to vector3

Vector3 letter = GameObject.FindWithTag ("Player").transform.position;

//position of the slot object to vector3

Vector3 slot = GameObject.FindWithTag ("Respawn").transform.position;

void Update()

{

  //Use to detect collision and if they are collided they will automatically overlap

  distance = Mathf.Sqrt(((letter.x - slot.x) (letter.x - slot.x)) + ((letter.y - slot.y) (letter.y - slot.y)));

  if (distance < letter.x - slot.x) 
  {
      letter = new Vector3(slot.x,slot.y,slot.z);
  }

}

When i was trying to run the program, the program still worked; however, my code did not work as I wanted to. Any ideas why it did not work? I know there is something wrong with the code. I am new to Unity, so I could not figure it out.

For the detection codes, the way I used is for the circle object, not sphere object, but I think sphere or circle only have 1 radius. Thus, I applied the circle formula in this case.

Comment
Add comment · Show 3
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 MrSoad · Nov 14, 2014 at 06:45 PM 0
Share

I'm not totally sure what you are doing and what has gone wrong but my best guess is this. I think you are tying to use one cube as a container for the other, cubes(with box colliders) are solid objects(imagine a set of solid wooden building blocks), and as a result you will get an unwanted result if you try to put one inside the other. What happened when you ran this?

avatar image BiTimup · Nov 14, 2014 at 09:23 PM 0
Share

Thanks so much for replying me.

The idea was just like you said that whenever one box touch another box, the one was touched become the container of the other. However, the one was contained has one face of the cube visible.

The game that i am trying to make is i have random letters, and i try to push the cubic letter into cubic slot, so that those letters gave a meaning.

I have done with most of the parts, I only got stuck with how to make the cubic letter fit into the cubic slot whenever they touch each other.

When I tried to run those code above. The program still ran, but gave me some error messages.

ArgumentException: FindGameObjectWithTag can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, ins$$anonymous$$d move initialization code to the Awake or Start function. UnityEngine.GameObject.FindWithTag (System.String tag) SwipeObj..ctor ()

avatar image MrSoad · Nov 14, 2014 at 09:34 PM 0
Share

$$anonymous$$ake sure you disable the collider on the one that you put inside, but this is not you issue. You need to post you full code for this script then hopefully someone can help, thanks

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Get distance from all objects in an Collider[] and compare 1 Answer

Internal collisions 1 Answer

Having trouble using Physics.OverlapSphere 1 Answer

OnCollisionEnter2D not working? 2 Answers

how to check if one object is colliding with another 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