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 ebersys · Mar 16, 2014 at 09:32 PM · transformparentmoving

Parenting player on top of moving object, player won't move

I have a simple problem, I have a moving (speed not constant, sliding on an inclined floor) box, when I jump my 'player' on top of it, my player won't move with the box, and eventually falls out

I have seen several people with the problem, and the solution seems to be simple, set the player's parent to the box, I've done that in many ways, from different events, and can't get it to work, the events run fine, the parent gets set, but the player won't move with the box

Here's some code for the Box script, the commented code are other things I've tried, I have also tried adding the events on the player side, with the same results:

 void OnCollisionEnter2D(Collision2D collision) {
         if (collision.WithPlayer()) {
             //player was set as GameObject.Find("MyPlayer").GetComponent<MyPlayerControl>();
             //Debug.Log("Player engaged with: "+player.transform.parent.name);
             //player.transform.parent = transform;
             collision.transform.parent = transform;
             //Debug.Log("Engaged");
         }
     }

 void OnCollisionExit2D(Collision2D collision){
         if (collision.WithPlayer()) {
             collision.transform.parent = originalParent.transform;
             Debug.Log("Dis-engaged");
         }
     }

The code executes just fine, it just doesn't produce the behavior I'm looking for

Here are the properties of the box: ![alt text][1] [1]: /storage/temp/23699-screen+shot+2014-03-16+at+2.57.14+pm.png

And these are the properties of my player alt text

Perhaps some properties are conflicting, any pointers would be appreciated

screen shot 2014-03-16 at 2.58.57 pm.png (94.4 kB)
screen shot 2014-03-16 at 2.57.14 pm.png (78.9 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 robcbryant · Mar 16, 2014 at 11:51 PM 0
Share

I always have problems with this. You could try something along the lines of this:

EDIT: If the playerobject is parented to the platform you might have to modify the positions to reflect the local values--other wise you might get a value of 50 for the center of the platform and a value of 1 for the playerobject rather than a 51 global

    Update(){
 
     //first get the difference between the center of the platform and the playerobject.
     
     movementUpdate = new vector3(Player.transform.position.x - Platform.transform.position.x,0,0); //This will yield either a negative or positive x modifier--positive if player is to the right of the center and negative if to the left
     
     //Once the platform moves--update the players x axis(I'm assu$$anonymous$$g gravity is handling the y although parenting the playerobject to the platform should handle this as well)
     
     Player.transform.position = newVector3(Platform.transform.position.x + movementUpdate,Player.transform.position.y,Player.transform.position.z);
     
     //now move the controller like normal--and hopefully it will allow you to move the character along the x axis relative to the center of the platform.
     
     CharacterController.$$anonymous$$ove(input$$anonymous$$ovement);
 
 }

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

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

Moving parent to position of child 0 Answers

moving child objects in hierarchy and keep stacks/sorting? Help needed 0 Answers

C#, expensive or inexpensive? 1 Answer

Properly Rotating Child Objects by Script 1 Answer

Problem retrieving transform.position after parent rotation 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