- Home /
Missiles attached with FixedJoint cause too much torque for airplane physics
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[i]);
}
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.
Is there a known solution around this?
Answer by JVene · Sep 03, 2018 at 07:01 PM
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.
Because my game imitates RC-controlled aircraft, I don't want a realistic aircraft mass, but I will check what happens. This could also have to do with the reduced size of the object (though that really doesn't make sense, because a small distance from a CG produces little pull; however, we get into since the airplane is smaller, the forces applied might differ...)
I like your idea about the center of mass, in the case where getting more detailed with the weight of things is more than just chucking in or removing a few grams.
I'm giggling over the idea of an RC controlled aircraft that actually shoots missiles.
Yes, in my imagination they're plastic sound-guided compressed air rockets ;)
Your answer
Follow this Question
Related Questions
Spinning a sphere in place causes unwanted velocity. 1 Answer
Aligning 2 Quaternions Using Torque 1 Answer
Is there any way to keep increasing an object's angular velocity? 1 Answer
Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers
Physic Torque Hinge joint problem 0 Answers