HoverMovement Component

HoverMovement

The HoverMovement Component is responsible for providing your vehicle’s forward and lateral movement. It continuously calculates and applies the correct physics forces necessary to move the vehicle’s Rigidbody in the desired direction at the desired speed.

To move the vehicle, simply set the ForwardSpeed and/or LateralSpeed properties or call the SetSpeedNormalized function (see the API docs for more information) to indicate the speed at which you’d like the vehicle to move, and the HoverMovement Component takes care of the rest. This makes it easy to drive the vehicle from user input or even an AI script.

Physics

Target Rigid Body

Specifies which Rigidbody instance the component will operate on. If this field is left empty, on startup the HoverMovement component will attempt to obtain a reference to a Rigidbody component on the same GameObject.

Drift Cancellation

Specifies the amount of momentum cancellation that will be applied. Higher values will result in the vehicle coming to a stop quicker, while lower values will cause the vehicle to drift longer before coming to a stop. If this value is set to zero, no momentum cancellation will be performed, and the vehicle will drift forever in the last direction of movement.

Perhaps more importantly, drift cancellation is also used when the vehicle is cornering, to counter the sideways drift that results from the previous forward movement. In this case, higher DriftCancellation values will result in sharper turns with less sideways drift, while lower values will result in wide cornering and more sideways drift.

hovermovement-physics-section

Speed Limits

Max Forward Speed

The maximum speed (in meters per second) that the craft can move forward.

Max Reverse Speed

The maximum speed (in meters per second) that the craft can move in reverse.

Max Lateral Speed

The maximum speed (in meters per second) that the craft can move laterally (strafing).

hovermovement-speed-section

A Note Regarding Speed Limits

As the vehicle begins to approach any of these speed limits the physics forces being applied will begin to decrease until, by the time the vehicle has reached speed limit in a given direction, no more force is being applied at all in that direction (as it takes no more force to reach the indicated speed limit).

If Momentum Cancellation is enabled, a vehicle traveling faster than the indicated speed limit will be clamped to the speed limit by the application of momentum-reducing force.

Force Limits

Max Forward Force

The maximum amount of force that can be applied to the RigidBody in the forward direction.

Max Backward Force

The maximum amount of force that can be applied to the RigidBody in the backward direction.

Max Lateral Force

The maximum amount of force that can be applied to the RigidBody in the sideways direction.

hovermovement-force-limits-section

A Note Regarding Force Limits

As you might expect, the Force Limits above must each be large enough to be able to accelerate the vehicle’s mass to the maximum velocity (see Speed Limits) in the given direction within the desired amount of time. Smaller values will take longer to reach the desired speed, while larger values will reach the desired speed faster. These forces are also used during Drift Cancellation. The Estimate Forces button will provide reasonable starting values for these fields if you are unsure how much force is needed.

Power Curves

Enable Power Curve

When set to TRUE, the animation curves below will be applied to the component’s force output. This value defaults to FALSE.
In most cases, use of these power curves will not be necessary, as the movementPID configuration already provides a great deal of flexibility, but they have been included for those situations where a finer level of control is desired.

Forward Power Curve

When EnablePowerCurve is TRUE, this animation curve will be used to modify the component’s force output in the forward/backward direction.

Lateral Power Curve

When EnablePowerCurve is TRUE, this animation curve will be used to modify the component’s force output in the left/right direction.

hovermovement-power-curves-section

Computation

Movement PID

The movementPID field configures the feedback control that is used to calculate the actual forces applied to the Rigidbody at any given point in time.  Specifically, it configures a generalized PID Controller (Proportional/Integral/Derivative controller) that can be tuned to provide a wide range of physics behaviors.

The proportional term (P) controls how quickly the hovercraft reaches the correct velocity. The derivative term (D) influences how quickly the vehicle recovers from speed changes caused by outside influences (such as collisions).

Although it looks complicated at first glance, HoverKit includes the ability to automatically determine the starting values that can be used for your vehicle, and with a little experimentation it quickly becomes obvious how to tweak the values to achieve the behavior you desire.

P Factor

This value determines how quickly the vehicle will adjust to arrive at the proper physics solution for moving at the desired speed, with higher numbers achieving the correct velocity faster than lower numbers. For instance, higher numbers might result in achieving maximum speed within a very short time (great for racing), while lower numbers might result in taking much longer to achieve maximum speed (more appropriate for tanks).

From 100% to 200% of the vehicle’s Rigidbody mass will provide a good starting point for experimentation, or use the Estimate Forces button to generate default values.

D Factor

In the case of the HoverMovement component, the dFactor value provides control over how quickly the system responds to external conditions like a collision, with higher numbers resulting in faster recovery, while lower numbers can result in a more pronounced loss of speed.

This value will typically be much lower than the P value, often not more than 5% of the P value.

hovermovement-computation-section

Code Examples

Using the SetSpeedNormalized function with direct user input to set the movement speed:

 void Update()
{
    var moveController = GetComponent<HoverMovement>();

    var moveSpeed = Input.GetAxis( ForwardInputAxis );
    var lateralSpeed = !string.IsNullOrEmpty( LateralInputAxis ) ? Input.GetAxis( LateralInputAxis ) : 0f;

    moveController.SetSpeedNormalized( moveSpeed, lateralSpeed );
} 

Using the ForwardSpeed and LateralSpeed properties to set the vehicle speed directly:

 void Update()
{
    var moveController = GetComponent<HoverMovement>();

    var moveSpeed = Input.GetAxis( ForwardInputAxis );
    var lateralSpeed = !string.IsNullOrEmpty( LateralInputAxis ) ? Input.GetAxis( LateralInputAxis ) : 0f;

    moveController.ForwardSpeed = moveSpeed * moveController.MaxForwardSpeed;
    moveController.LateralSpeed = lateralSpeed * moveController.MaxLateralSpeed;
} 

HoverMovement API Documentation

View the API documentation for the HoverMovement Component online.