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 Rbrons · Nov 14, 2016 at 02:24 PM · c#physicscollidergameobjectsplacing

Doubt about placing items on tables

Hello everyone. I have a question about how to place items on a table exactly in the center of it in a fixed way, which the player can pick up or place whenever he wants. An example is as seen in the game "Overcooked"... seems like its works like a grid.

alt text

What should I do? I already have the item with rigidbody, and the table also, both with colliders. The player already collects the item as well.

Another example I made...

alt text

Thank you all!!

overcooked.jpg (131.4 kB)
test.jpg (34.7 kB)
Comment
Add comment · Show 6
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 itsharshdeep · Nov 14, 2016 at 03:01 PM 0
Share

Hi,

I don't know any better solution for now. But the following is the first approach hit in my $$anonymous$$d: When you need to place the item on the table or any object.

  • $$anonymous$$ake Child of the Object.

  • (With the help of little math calculations) Get the bounds of the object (like a table) to the height of the table and ADD object's height (which need to be placed ) so that it should come at the top.

  • You can skip the above step if your player always holds the objects with very much. Because after dropping the objects it will always come at the top.

But now as I'm writing this answer there are numbers of questions co$$anonymous$$g in my $$anonymous$$d. Like: How you want to show the effect?

Let's say you have the ball then you need to show the bounce effect or not.

  • Is your game grid-based or freely movement character is present?

  • If it is grid movement. Suppose the player have a Cube now he wants to Drop the cube on the table. You want to instantly snap the cube to the table or it's a slow motion effect.

Lots more questions are present in my $$anonymous$$d now. So Sorry If I confused you. But there are plenty of methods. which may vary upon the requirements of the game.

avatar image itsharshdeep · Nov 14, 2016 at 03:16 PM 1
Share

In the reference game ( overcooked ) they have used the snapping technique which is very simple.

  • Just detect the table ( like by making the collider bigger from the top side) or on the which item is get triggered in the Collider of the dropping object ( let's say ball in this case)

  • $$anonymous$$ake child

  • To remain at always on top and which proper snap position. I have two approaches:
  1. I will put one empty object on above the table. This empty object is placed in such a way so that I can give his positions to the ball. So that it always looks pretty cool and on the table with proper alignment.

  2. Generic way. Find the height & center of the table from the Bounds. Add the scale of the ball in it. It will return you a position on which you have to place the ball. ( Sorry it's hard for me to explain this formula) .

avatar image Rbrons itsharshdeep · Nov 14, 2016 at 06:06 PM 0
Share

@itsharhdeep

Thanks for the attention :)

Its exactly what you said, Im trying to make a simple project tha uses the logic of Overcooked (I'm a fan), putting items on tables, manipulate them, grab and drop all the time over the stage. The player is free to walk over the place, but the items on tables stay fixed.

I did what you said, I put a empty gameobject above the table, parent the item to the table and pass the position/rotation to item of empty gameobject... That's ok but, assu$$anonymous$$g there will be different sizes of items, some of them keep "floating" or "inside" the table, because there is no direct contact to table...

So... the second way, the generic way as you say... The script is too complicated to implement the formula?

avatar image itsharshdeep Rbrons · Nov 14, 2016 at 08:32 PM 0
Share

I have made a basic script which might help you to get the bonds and make the child. The script is attached in the answer's section. If you need I can also send the package which contains the TestScene.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by itsharshdeep · Nov 14, 2016 at 08:16 PM

Following is the script I have made in the hurry up. You can check this. I tried to set random scale and positions and it worked. But there might be the special cases which need to consider as per the requirements

 using UnityEngine;
 using System.Collections;
 
 public class TableChild : MonoBehaviour
 {
     MeshRenderer meshRenderer;
 
     void Start ()
     {
         meshRenderer = gameObject.transform.GetComponent<MeshRenderer> ();
     }
     
     void OnCollisionEnter (Collision col)
     {
         MakeChild (col.gameObject);
     }
 
     private void MakeChild (GameObject go)
     {
         //getting externs bond
         Vector3 goBonds = go.GetComponent<MeshRenderer> ().bounds.extents;
 
         //Setting the positon of the object
         go.transform.position = new Vector3 (gameObject.transform.position.x,
             meshRenderer.bounds.extents.y + goBonds.y + gameObject.transform.position.y,
             0);
         // After setting the position then making the child
         go.transform.SetParent (gameObject.transform);
         
         go.GetComponent<Rigidbody> ().isKinematic = true;
     }
 
 }
 
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 Rbrons · Nov 15, 2016 at 12:12 PM 0
Share

Its works here!

I made some modifications in it for my project and it worked well.

Thank you so much @itsharshdeep

avatar image itsharshdeep Rbrons · Nov 15, 2016 at 12:41 PM 0
Share

:) No Problem Happy to help :)

You can let us all know the changes you have made in the script if they are generic and required to make the script more stable and usable.

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

How to move an object on a terrain that will always stay on top of the terrain? 2 Answers

How to fix this problem? 1 Answer

How To how ?? 2 Answers

Collision Detection with DrawMeshInstanced 0 Answers

Ignore collision based on 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