I have an airplane controlled by the heavily modified AeroplaneController.cs physics. This works very well, and it has been tuned to turn relatively sharply.
However, I want it to carry missiles that are also physics-based. So I created a missile prefab and attached a couple to the airplane in code, like so:
// Add a missile to each launch position
for(int i = 0; i < m_MissileLaunchPositions.Length; i++)
{
GameObject missile = m_AAMissilePrefab;
// Assign the fixed joint to the airplane
missile.GetComponent<FixedJoint>().connectedBody = m_Rigidbody;
// Add the missile to the rack
Instantiate(m_AAMissilePrefab, m_MissileLaunchPositions*);*
} This works nicely. However, even if the mass of each missile is only 0.0001, (the airplane’s being 0.54), and drag/angular drag are reduced to zero, the airplane’s maneuverability is hampered dramatically. Creating a test case which launches the missiles: public void Launch() { // Detach the missile from the airplane Destroy(m_Joint);
// Play the escaping air sound m_AudioSource.Play(); } Proves that maneuverability is restored once the missiles are detached. I’d like to use a FixedJoint instead of manually adding/subtracting from my airplane’s Rigidbody weight when missiles are shot, because this adds weight to one side or the other of the airplane, instead of to the center of mass of the airplane’s Rigidbody. But my issue here is that the torque caused by the missiles is by far exaggerated compared to their weight. [123803-unity-fixedjoint.jpg|123803]* Is there a known solution around this?
*
Using PhysX outside of Unity, and within Unity (it’s the engine under the hood here) demonstrates rather clearly there is no great solution here.
Frankly, joints are not that realistic for a wide range of expectations. They do what they do, and they have all sorts of ‘issues’ relative to expectations. and that applies to everything from fixed joints to configurable joints. There are a set of ‘articulated joints’ recently added to PhysX, but they’re not exposed in Unity at this time, and may offer some useful difference in the future, but I don’t know how applicable they will be to your observation and inquiry.
This isn’t really the all that bad a thing as it seems. We generally make assumptions about the expected behavior of concepts, like joint attachments, which aren’t actually provided by the physics engine, because we tend to think these systems ought to perform according to our expectation of a real systems, but they’re not simulations of reality. They mechanisms that facility the creation of a kind of ‘puppet show’. This means we are generally reduced to using what’s available to ‘fake’ the kind of results we expect. This isn’t so much a failure of PhysX as it is the sort of compromises required for real time physics calculations.
That said, you might find some relief by making the plane a bit close to a real mass than you have. The mass unit in Unity is 1 Kg, so your entire plane is being simulated as if it were only about half a Kg, which may do better toward the range of 100 Kg or more. This will impact everything you already have working, but as an experiment it may lend some useful information.
If that doesn’t work, you’ll need to explore Rigidbody’s centerOfMass property, relative to your concerns about eccentric mass distribution. There may not be a better solution. In my own efforts with various vehicles and objects, I’ve not really found one.