- Home /
How do I get an asymmetrical spaceship to rotate correctly using torque?
My issue can be illustrated with this video:
http://www.youtube.com/watch?v=NZQ4X1YL1Vo
Whenever the profile of the ship perpendicular to the axis of rotation is asymmetrical, it has a weird wobble. The ship in the video wobbles when adjusting yaw, but pitches just fine. I can also make a ship that yaws fine but pitches weird (for instance, a ship that looks flat from the side but looks like an L from above).
The code running here is essentially:
gameObject.rigidbody.AddRelativeTorque(Vector3.up*PitchYawForce);
I want to use the physics engine instead of directly modifying the rotation so that the ship can be knocked off course by physics interactions that won't get negated because the player is turning. Simply making the ship symmetrical isn't an option because the player can build the ship by putting the modules together, and I would like to leave them the creative freedom to build asymmetrical ships.
Note that I move the child objects of the ship relative to the parent object such that the object's pivot is identical to the center of mass.
Answer by IanH · Jul 25, 2014 at 05:42 AM
My suggestion would be to give the additional components 0 mass (and no rigidbody), but instead give them a mass variable in a script and a mass variable in the "core" component with the rigidbody. You could then add/remove the child mass variables to that of the parent with an "OnAttach/OnUnattach" function and update the rigidbody.mass.