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 CorruptedTNC · Apr 04, 2014 at 11:03 AM · platformmovingparenting

[C#] More elegant solution to making player move with moving platform?

Using Unity version 4.2.1f

My latest project is a 3D puzzle game which makes use of many moving components. When activated they would rotate or move from point to point. Because of this I needed a way for the player to stay "attached" to them to prevent the platforms from sliding out from under them since some of them move very quickly.

Originally I intended to use OnTriggerEnter and OnTriggerExit events to mess with parenting of the game object. I quickly discovered that when the object is parented OnTriggerExit is no longer fired, a change that the ask section tells me was changed in 3.2. I don't particularly understand how that works but working around it was fairly easy. The only problem is that it feels a little cheap (for lack of a better word). I'll of course implement tag checks to prevent it parenting any other objects that pass through it.

Is there any more elegant solution, or one that would be considered "better" for handling this?

 void OnTriggerStay(Collider col)
 {
     if(col.CompareTag("Player"))
     {
         if(TP_Controller.CharacterController.isGrounded)
         {
             //Parent object rather than the empty object containing the trigger.
             col.transform.parent = this.transform.parent;    
         }
         else
         {
             col.transform.parent = null;    
         }
     }
 }
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
0

Answer by HarshadK · Apr 04, 2014 at 11:41 AM

You can think of using Fixed Joint if you are using rigidbodies.

Unity Reference Manual states that:

Fixed Joints restricts an object's movement to be dependent upon another object. This is somewhat similar to Parenting but is implemented through physics rather than Transform hierarchy. The best scenarios for using them are when you have objects that you want to easily break apart from each other, or connect two object's movement without parenting.

But one issue with using this is that it restricts the movement of objects. If that is not an issue with you and you are using rigidbodies then Fixed Joint is the way to go.

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 CorruptedTNC · Apr 04, 2014 at 12:04 PM 0
Share

Unfortunately I wanted the player to be able to move independently of the platform but to be "dragged" along with it, so that the player can walk off the platform or jump off at any point. Thanks for the useful information though, that's bound to come in handy further down the project.

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

21 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

Related Questions

movement inside a train problem 1 Answer

How do I have my first person travel along with a moving object? 1 Answer

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Moving Platform Moves instantly. 1 Answer

Player won't stay on moving floor 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