• 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 Random Indie · May 08, 2010 at 07:05 AM · rotationrigidbodyparentingtranslation

Children ignoring Parent control. [Solved]

I asked this question on the forums but it seems to have been lost at sea, and considering it's something of a question that shouldn't require debate I figured this would be a better place to ask. I've poured over everything I could find (forum threads, other questions here) about rigidbodies and parentage but I haven't found much, some stuff about how you shouldn't put rigidbodies on children (in other situations) but the docs said it was good so here goes.

Setup

I am developing a game set in space and would like to move the "world" around the player rather than the other way around because of floating point errors that start happening around 10K units. To accomplish this I have set up nested coordinate systems using parenting.

I have a rigid body called the Local Rotation Group that remains stationary at the origin with the player. It has a rigidbody so I could use torque and drag to better simulate player rotation. This works exactly as expected.

I have another rigid body called the Local Translation Group. This object is used to simulate translational movement of the player (ie: player pushes forward, the translation group moves backward). This also works perfectly.

Combined these should simulate the player moving and rotating around the level.

Problem

However, the translation group stops responding to the rotation group's (it's parent) rotation when the script controlling the translation is turned on. If disabled before play, all objects in the translation group rotate as expected, but when the script is enabled they snap back to their original position and no longer rotate around the player (although movement controls still work), upon disabling the script they once again respond to rotation. If enabled (with the addrelativeforce function commented out) again the translation group rotates with the parent.

In the docs on rigidbodies the section on Parenting describes the exact effect I'm going for but it doesn't seem to work. Everything in the scene has a rigidbody. The offending code (and line I mentioned commenting out) seems to be:

//Translation Group code
void FixedUpdate() 
{
    float input = Input.GetAxis("Forward Thrust");
    if(this.Invert == true)
    {
        input *= -1;
    }
    this.rigidbody.AddRelativeForce(input * Vector3.forward * this.ForwardThrust);
}

For completeness:

//rotation group code void FixedUpdate () { rotationX = Input.GetAxis("Mouse X") * sensitivityX; rotationY = Input.GetAxis("Mouse Y") * sensitivityY; if(this.InvertY == false) { this.rotationY *= -1; }

 if(this.InvertX == true)
 {
     rotationX *= -1;
 }

 Vector3 t = new Vector3(rotationY,rotationX, 0);
 this.rigidbody.AddRelativeTorque(t.normalized*this.Torque);

 float input = Input.GetAxis("Roll");
 if(this.InvertRoll == true)
 {
     input *= -1;
 }
 this.rigidbody.AddTorque(0,0,-1 * input * this.RollThrust);

}

Hierarchy:

alt text

(the cubes are so I can see what's happening in each group and contain rigidbodies)

Question

Is there a solution? Is this even the right approach? If any clarification is needed please let me know.

Cheers and Thanks!

Comment
Add comment · Show 8
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 Random Indie · May 08, 2010 at 10:21 AM 0
Share

Just realized I'm doing too much work in the rotation group code, not that it solves the problem...

avatar image spinaljack · May 08, 2010 at 11:07 AM 0
Share

Are you using localPosition? That'll make sure movement is relative to the parent

avatar image spinaljack · May 08, 2010 at 11:08 AM 0
Share

Are you using 2 rigidbodies? They will behave independently of each other, I'm not sure what you want to achieve with this.

avatar image spinaljack · May 08, 2010 at 11:09 AM 0
Share

Try adding a hinge joint to restrict motion to a single axis on the child

avatar image Random Indie · May 08, 2010 at 11:20 AM 0
Share

@Spinaljack: I was hoping to handle everything through the physics system. From what the docs say if a child of a rigid body has a rigid body the child with get dragged along with the parent but it's collisions will still happen regardless of the parent. Which is exactly what I was going for, but it doesn't seem to work. The objects that do the rotating and translating don't have colliders, they're just used as origins for their respective spaces.

I've never seen localPosition, I'll have to look into that and let you know.

Show more comments

1 Reply

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

Answer by Mike 3 · May 08, 2010 at 02:34 PM

won't this approach just give you floating point precision problems in reverse?

when your playzone is 10k units away, you'll start hitting issues.

the usual technique is to have your ship move like normal, but when it hits a boundary (say 1k units), it moves both the play area and the player back by that value, and then store what global space you're in

that way your universe is segmented into smaller grid blocks, which can help in many other ways too

Comment
Add comment · Show 3 · 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 Random Indie · May 08, 2010 at 03:08 PM 0
Share

Yep, but I was hoping that if it wasn't happening right in front of the player they wouldn't notice if the physics isn't behaving correctly.

The method you described is what I just switched over to and it seems to work perfectly except the trail renderer leaves a nice long trail to the middle of nowhere when the boundary is hit.

Just one question: "then store what global space you're in" Do you mean what grid space? I came up with a sneaky way of never having to actually deal with that :)

avatar image Random Indie · May 08, 2010 at 03:09 PM 0
Share

Almost forgot, regarding the child/parent rigidbody problem, am I crazy or do the docs say what I was doing should have worked?

avatar image Mike 3 · May 08, 2010 at 03:54 PM 0
Share

to be honest i'm not sure - you're using non kinematic rigidbodies for the entire universe which is really going to go creepily wrong with collisions, especially if you have other objects moving with rigidbodies inside

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Adjusting Roll and Pitch with Velocity 0 Answers

Prefab changing dimensions when parent changed 1 Answer

Issues Rotating an object 0 Answers

Rigidbody.AddForce and incorrect rotation 2 Answers

How can I rotate RigidBody and not violate physics? 3 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