Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by harada_unity861 · Jul 19, 2021 at 01:21 AM · collisionmovementontriggerenterparent and childstacking

Make object(s) stack vertically.

Hello, I'm working on Unity 3d / C# stuff and have a question. Here is the image of the current project.

alt text

The brown cube object on the left bottom is named "Player", which I can move anywhere in the Plane. Other yellow and light gray cylinders are named "Ingredient". and I attached Ingredient.cs script. In the script, there is an OnTriggerEnter event, so when the Player object collides with an Ingredient, I can do something.

What I want to do next is when the Ingredient collides with the player, place and stack the ingredient on top of the Player object, and then move with the Player object (kind of like making a tower.) Things I have done were making an empty object called "PlayerContainer", and when the Ingredient object is collided by the Player object, set Ingredient parent to PlayerContainer.

alt text

As the image shows, now I can make the Ingredient object parent to PlayerContainer, but I cannot stack the Ingredient object onto the player and move together.

 public class Ingredient : MonoBehaviour
 {
   GameObject player;
   GameObject playerCont;
   GameObject topIngredient;
   float playerHeight;
 
   void Start()
   {
     playerHeight = 0f;
   }
 
   void OnTriggerEnter(Collider other)
   {
     PlaceOnTopOfPlayer(other);
   }
 
   void PlaceOnTopOfPlayer(Collider other)
   {
     player = other.gameObject;
     playerCont = player.transform.parent.gameObject;
     playerHeight = playerCont.transform.lossyScale.y;
 
     iTween.MoveAdd(this.gameObject, iTween.Hash("y", playerHeight, "time", 1.0f, "oncompletetarget", this.gameObject, "oncomplete", "CombinedWithPlayer"));
   }
 
   void CombinedWithPlayer()
   {
     numOfIngredientCombined += 1;
     this.gameObject.transform.SetParent(playerCont.transform);
   }


So could you tell me how can I make the Ingredient object move together with the Player after this? Also, do I really need to put Ingredient object as a child of PlayerContainer?

※ I didn't add Rigidbody to Ingredient object but Player object.

screen-shot-2021-07-19-at-94301.png (161.8 kB)
screen-shot-2021-07-19-at-100251.png (136.3 kB)
Comment
Add comment · Show 1
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 UsmanERA · Feb 15 at 11:31 PM 0
Share

https://youtu.be/lEwo2okj_Rg

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

272 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 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

Need some help programming basic AI movement 0 Answers

OnTriggerEnter doesn't work if the colliding object is not moving. Translating it by (0,0,0) fixes it. What's the problem? 4 Answers

Collisions between two objects are not being detected. 1 Answer

Object starts to swerve/gets derailed after collision with a collider. Please help! 0 Answers

Is there anyway to move a player back to the start of a level/section of a level when they collide with an object (enemy/trap)? 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