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 /
avatar image
0
Question by DavidJarman1991 · Apr 28, 2021 at 10:02 PM · movementrigidbodymovement scriptplatformrigidbody.addforce

Child object not moving with parent

Hi,

I'm sure im missing something obvious here, however I have trawled through every tutorial and post i can find but cant seem to crack it. Any help would be appreciated.


I have a parent object called "Ship" and a child called "Player". The end goal is for the ship to be able to move and be effected by physics, while the player can run around on deck.

In my current setup I cant stop the player sliding off the back of the ship when I add force. My understanding is that by making the player a child of the ship it should move with it, however the only way I have found to do this is to make both objects kinematic rigidbodies, which will cause me issues as I want the ship to be affected by physics.


The ship object has a rigidbody attached and I am moving it by adding force (the intent is for this to act like an engine):

 void Update()
     {
         //Move the RigidBody forwards at the speed you define
         m_Rigidbody.AddRelativeForce(Vector3.forward * thrust);
     }



The player has a script attached that allows it to move/look around etc. The code for the actual movement is below, (obviously there is supporting code around this). It works fine for a normal FPS style game, however is possibly not the right method for this case.


The player does not have a rigidbody attached.

 characterController.SimpleMove(Vector3.ClampMagnitude(fwdMovement + rightMovement, 1f) * _speed);

alt text

ship.png (122.0 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by golaod · Jun 09, 2021 at 08:00 PM

It's an old topic, but I just had the same issue. I moved my old project to new unity and new render pipeline system and same script, same player and same platform stopped working.


After checking all the topics with rigidbody, OnTriggerStay, position correction and so on, I found out that there is 'auto sync transforms' option which was not enabled in my new project. When I reenabled it, things went back to normal. (Edit -> Project Settings -> Physics (or Physics 2d) -> Auto Sync Transforms

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 mpbMKE · Apr 15 at 11:32 PM 0
Share

Thanks, this is exactly what I needed! I haven't seen anyone else in any forum mention Auto Sync Transforms, and I'd wasted at least an hour trying to figure out why my object children weren't moving with their parents.

avatar image
0

Answer by HellsHand · Apr 28, 2021 at 10:15 PM

A suggestion that may be worth trying, adding force to both the player and the ship at the same time when the ship moves, though you may have to play around with the amount of force for the player.

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 DavidJarman1991 · Apr 29, 2021 at 05:44 PM 0
Share

Thanks for the reply.


I struggled with adding force in the same direction, it was very unpredictable and in many cases would not add force at all (I added a rigidbody to the player).


However it got me thinking about using the transform function to always keep the player on top of the ship by adding its transform to its own.


Theres definitely a more elegant way of writing the code below, but im keeping it longhand for now to try and help visualise whats happening:


This keeps the player nicely on top of the ship, however stops you moving entirely from that point as you always reset to 0:


 transform.localPosition += new Vector3(0,0,0);



So I have tried this, however this fires you into the distance as its always adding. I think i need to find a way of storing the local position separately and then use that. Possibly that will require a re-think of how the character moves, but potentially I could move the character in local space and then just add the current location of the ship to that.


 transform.localPosition = new Vector3(parentShip.transform.position.x + transform.position.x, parentShip.transform.position.y + transform.position.y, parentShip.transform.position.z + transform.position.z);
     







avatar image
0

Answer by cotterdev · Jun 09, 2021 at 11:59 PM

When adding force, this should be done in FixedUpdate instead of Update. Anything to do with physics should be executed in FixedUpdate.

Comment
Add comment · 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

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

217 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

Related Questions

How to make a rigidbody move in the direction of finger(x,y,z) 1 Answer

Implementing Counter-Movement 0 Answers

How do I stop unwanted rotations? 4 Answers

How to move Character with AddForce 1 Answer

Top Down Mobile Game movement (rb or CC) 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