Crystal Entity Layer: 4.3.6 Hover

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 4.3.6 Hover

The mesh property class can be used to assign a 3D model to an entity. This property class defines a visual representation for an entity. This property class, defines a hovering object when used in conjunction with ``pcmechobject'`.

#### Property Class Details

- Name: ``pchover'`
- Factory ID: ``cel.pcfactory.hover'`
- Interface: `iPcHover`
- Header: ``include/propclass/hover.h'`

#### General Information

A Hovering object can be something like a hovercraft or a anti-gravity ship. As well as hovering your object, it will also align it to the terrain, so that as it goes down a hill, the ship will also tilt.

This property class requires you to load it with an entity, which has a ``pcmesh'` property class to act as the terrain it hovers over.

#### Setting the Terrain

There are 2 ways to set the terrain mesh in ``pchover'`:

- Assuming you have the `iPcMesh` object, call `iPcHover->SetWorldMesh(pcmeshobj)`
- Or you can use the entities name, as in `iPcHover->SetWorld("ent_level")`

This step is crucial, if you forget to do it the hovering system will not work.

#### Setting the Upthruster Function

Instead of using the default upthruster function, you may want to provide your own reactionary calculator.

    // CEL Includes
    #include "tools/stabiliser_dist.h"

    class CustomUpthrusterFunction : public celStabiliserFunction
    {
    public:
      float Force(celHoverObjectInfo obj_info)
      {
        /* when the height of the object
            is less then 2, use an
            upthrust force of 8 */
        if (obj_info.height < 2)
          return 8.0;

        return 0.0;
      }
    };

Then to insert into the property class you would do

    pchover->SetStabiliserFunction (new CustomUpthrusterFunction ());

At runtime, everytime the objects iPcHover is updated, your upthruster function will get called with information with the objects information on its state.

    struct celHoverObjectInfo
    {
      /**
       * The height of the object above the
       * ground in along the world's y axis.
       */
      float height;

      /**
       * The vertical velocity of the object
       * along the objects local y axis.
       */
      float yvel;
    };

#### angular correction

This refers to the object correcting its angle as it flies over terrain (facing downwards as it flies down hills).

The implementation of this is done by calculating the object's height at its center and then calculating the height away from the center. Using the differences in height and a bit of trigonmetry, you can see the angle of the object relative to the terrain.

- `iPcHover->SetAngularBeamOffset (float)` refers to how far away from the center of the object the second height test is done. Smaller values are better on more noisy terrain, but less accurate and more jerky, whereas larger values are more likely to approximate (that small bump won't get noticed). Values like 0.5 are usually small enough to suffice.
- `iPcHover->SetAngularCorrectionStrength (float)` is how fast the object corrects its rotation. High values and it will jerk extremely fast, smaller and it will hardly re-align. 1.0 is normal.
- `iPcHover->SetAngularCutoffHeight (float)` is the height at which the angular correction stops working - you obviously don't want a ship re-aligning itself with terrain as its flying in the air.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ]

This document was generated using texi2html 1.76.