Tuesday, February 24, 2009

Hard Object Weirdness (or Don't Count On Bugs)

ATTR_hard is the OBJ attribute that makes the geometry of an object mesh interact with X-Plane's physics engine.  ATTR_hard object has a long history of weird behavior, and its behavior in X-Plane 930 is no exception.

The History
  • Before X-Plane 815, hard surfaces acted horizontal regardless of the actual OBJ geometry.
  • From X-Plane 815-922, sloped hard surfaces work as expected, but vertical hard surfaces do not work.  Animation is ignored for hard surfaces.
  • Starting with X-Plane 930, animation commands affect hard surfaces.  However, vertical surfaces still do not work, and an animated surface does not create friction under the plane.  
(In other words, if you put the plane on a platform and move the platform horizontally, the plane will be pulled with the platform due to friction between the platform and the wheels.)

In all of these cases, what we have is a limited implementation that doesn't correctly capture all expected behaviors.  Why don't we have a better implementation?  There are two factors.
  1. In some cases a more correct implementation might take significantly more CPU power. It is important that we not raise the CPU requirements of X-Plane mid-version run.
  2. In some cases, we simply don't have a better implementation coded yet.  Remember that X-Plane is primarily a flight simulator.  My pilot friends tell me that it is bad form to collide the airplane with anything during flight.  So the goal of OBJ collisions is more to detect poor flying than to correctly model the resulting aftermath.  X-Plane is not GTA4!
What Do You Do With a Buggy Feature?

Very simple: don't use it if you can avoid it!  I don't mean "don't use ATTR_hard" - it has legitimate uses.  Rather I mean: don't depend on the buggy behavior as a feature.

For example, before 930, animation would affect the drawn but not physical OBJ.  I would say that given that bug, the only safe thing to do is to not animate hard objects.  Animating hard objects to take advantage of the schism between drawing and physics would be assuming that the bug will stay buggy forever.

What Can You Do Now?

In X-Plane 930 hard object animation is a lot better than it used to be, but still not quite correct.  The remaining limitations are:
  • There is no friction.  If you move a platform horizontally, the plane is not dragged along. So you can't really build horizontal elevators.  (You can build a platform that moves vertically and move the plane around that way.)
  • There is still not support for vertical hard surfaces.  Like before, to make a solid "wall", make the wall thick and make the top of the wall hard.  But bear in mind that the collision detection in this case is catastrophic; your plane will be heavily damaged by even minor contact with the wall.  X-Plane doesn't support horizontal collisions right now.
  • Hard surfaces are ignored for vehicles.  If you are replacing the car set, don't add hard surfaces - it might turn out that some future implementation does look at them - if that happened, how would you know what the CPU hit is?
Even given this limitation, you can now make a building with limited access controlled by animation; using a "deck" for the roof and a hard surface for the tops of the walls and the doors (which are animated) you can control access.


Alejandro Garcia said...

Ah...I whish x-plane were GTA4...
No, seriously I don't really understand why would we need a vertical hard surface. I'm sure there are lots of implementations but right now I can't see some.

If we talk about collisions, you can add a little horizontal surface so the plane will collide and it'll look as if the vertical object was the problem.

Benjamin Supnik said...

Alejandro, the issue is this: since X-Plane's collision logic is only vertical, if you very gently bump into the "top" of a door (modeled by the horizontal top of the door being a hard polygon) the collision strength is measured by how far below the door you are vertically. This results in a huge collision even if your plane is moving at one mile an hour.

In an "any-direction" collision model, we would test collisions in _all_ directions...allowing for a very small collision of the nose of the aircraft with the surface directly in front of it, instead of a huge one with the surface above it. That surface in front of it would of course have to be vertical.

In other words, the issue of vertical surfaces is closely tied to the issue of any-direction collision detection; without this feature, we correctly determinet that there IS a collision but INCORRECTLY judge how violent that collision is!

Anonymous said...

There is Grand Arche, part of Bretrand's Paris scenery. I tis a hollow building and it has a helipad at top. It had two issues: (i) Place a heli to that helipad, and it ended in the basement. (ii)one cannot fly thru the opening in the building.

Has any of these got better in 9.3?

Benjamin Supnik said...

Anon: neither should have changed in 930.

Re: flying under, the author must use ATTR_hard_deck to allow this. ATTR_hard_deck worked in 922 and works in 930, so if you cannot fly under the arch, the author has not yet taken advantage of this (relatively recent) capability in the sim.

Re: the helipad, this is a design limitation, not a bug. There is no way to specify a helipad on top of a building right now. 930 does not add this capability.

Photos said...

is it the same problem while beaching a seaplane or try to use a slip ? Any ways for an improvement to avoid huge collision behavior ?


Benjamin Supnik said...

I think the seaplane behavior is a different limitation - we don't track the ground and objects at the same time.