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 /
avatar image
1
Question by Winnppl · Sep 19, 2018 at 07:50 PM · collisiontriggerstacking

Stacking mechanic (Parenting Prefab to another prefab on collision)

Hello i'm working on building a stacking mechanic for my game.

what I want to happen is for my movable platform to catch and stack the falling objects as they collide with the platform. My idea was to make the falling objects a child to the platform when a collision between them happen and then it would "stick" to the platform while the player is still able to control the platforms side to side movement.

this is the code I am using at the moment, im able to get the platform to child the falling objects after a collision between them, but it wont stay sticking to the platform when I move around.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Stacking : MonoBehaviour
 {
 
     private void OnCollisionEnter(Collision stacking)
     {
         if (stacking.gameObject.tag == "track 01")
         {
             stacking.transform.parent = GameObject.Find("BurgerPlate").transform;
         }
     }
 
 }


any suggestions or other ways to accomplish this task?

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

2 Replies

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

Answer by TreyH · Sep 19, 2018 at 08:05 PM

Can you just disable the physics on it?

 private void OnCollisionEnter(Collision stacking)
 {
     if (stacking.gameObject.tag == "track 01")
     {
         stacking.transform.parent = GameObject.Find("BurgerPlate").transform;
 
         // It's moving because of its Rigidbody.
         stacking.transform.GetComponent<Rigidbody>().isKinematic = true
     }
 }
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 kevojo · Sep 19, 2018 at 08:15 PM 1
Share

Yep what he said should work - or you could also just remove the rigidbody altogether if you wanted to save a little bit on background calculations

 private void OnCollisionEnter(Collider stacking)
     {
         if (stacking.gameObject.tag == "someTag")
             {
                  stacking.transform.parent = this.transform; 
                      //or whatever object you want to be the parent
                  gameobject.destroy(stacking.getComponent<rigidbody>());
             }
     }



avatar image
0

Answer by Winnppl · Sep 19, 2018 at 08:40 PM

Thank you both! I implemented parts of each of your codes and it worked perfectly!

Much appreciation!

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 kevojo · Sep 19, 2018 at 08:44 PM 1
Share

Be sure to mark the best answer as the correct answer so it gets flagged as solved. Cheers!

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

157 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Activate trigger if items colected 1 Answer

If gameObject's center passes through a trigger? 1 Answer

Play Animation OnTriggerEnter 2 Answers

Targeting the GameObject I collide with? 1 Answer

Whats wrong with my score script 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