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:
(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!