Class AZagalaSpecExamplesHoverboardActor#

Inheritance Relationships#

Base Type#

  • public AActor

Class Documentation#

class AZagalaSpecExamplesHoverboardActor : public AActor#

Hoverboard System Under Test (SUT).

A deliberately simple hoverboard example. Each tick a single upward force is applied at the centre of mass, keeping the board floating at HoverHeight above the ground. The force compensates gravity and drives the vertical velocity toward the speed needed to close the height gap in TimeToRecover seconds. Throttle inputs add forward/backward force at the centre of mass; steering inputs apply opposite forward/backward forces at the two front corners (HalfExtent from the centre) to generate a yaw torque.

Hovering on four corner points instead needs much more logic, which this example avoids:

  • A corner force also rotates the board; the effective mass at a corner depends on the inertia tensor and lever arm, so independent per-corner corrections over/under-shoot and can become unstable.

  • Corrections must be decomposed into heave, pitch and roll (net force + torque) and then redistributed to the corners, with four points over-determining three degrees of freedom.

  • Tilt makes the vertical traces, point heights and point velocities inconsistent.

  • Clamping corner forces to push-only breaks the symmetry of the corrections.

  • Game-tick vs physics sub-step timing must be accounted for to avoid oscillation.

Physics timing note: forces added via AddForce / AddForceAtLocation accumulate during the current tick and are applied during the next physics sub-step. Observable effects (velocity, position) are therefore visible from the following engine tick onward.

Sign convention: Throttle +1 = forward, -1 = backward Steering +1 = right (positive Yaw), -1 = left (negative Yaw)

Components

TObjectPtr<UBoxComponent> HoverBox#

Physics tunables

float HoverHeight = 150.f#

Target hover height above ground in cm.

float TimeToRecover = 0.5f#

Time in seconds the hoverboard should take to reach HoverHeight.

float MaxHoverTraceDistance = 10000.f#

Maximum distance below the board at which ground is detected (cm).

float MaxThrottleForce = 500.f#

Peak throttle force (kg*cm/s^2) applied at the centre of mass.

float MaxSteerForce = 450.f#

Peak per-front-corner steer force magnitude (kg*cm/s^2).

TEnumAsByte<ECollisionChannel> RayCastChannel = ECC_Visibility#

Collision channel used for downward hover traces.

float MassKg = 20.f#

Physics mass override in kg.

float LinearDamping = 2.f#

Linear damping coefficient applied to the mesh.

float AngularDamping = 4.f#

Angular damping coefficient applied to the mesh.

float HalfExtent = 100.f#

Half-extent from the actor centre to the front steering corners in the XY plane (cm).

Input

void SetThrottle(float InThrottle)#

Set throttle in [-1, 1].

Positive = forward, negative = backward.

Parameters:

InThrottle – Throttle input; clamped to [-1, 1].

void SetSteering(float InSteering)#

Set steering in [-1, 1].

Positive = right, negative = left.

Parameters:

InSteering – Steering input; clamped to [-1, 1].

Query

float GetHeightAboveGround() const#

Line-trace straight down from the actor centre.

Returns:

Height above the ground (negative when below its surface), or 0 if there is no world or no ground is found.

float GetYawDegrees() const#

Returns current Yaw in degrees (UE convention: positive = clockwise from above = right).

Returns:

The actor rotation Yaw in degrees.

inline float GetThrottle() const#
Returns:

The current throttle input in [-1, 1].

inline float GetSteering() const#
Returns:

The current steering input in [-1, 1].

Public Functions

AZagalaSpecExamplesHoverboardActor(const FObjectInitializer &ObjectInitializer = FObjectInitializer::Get())#
virtual void BeginPlay() override#
virtual void Tick(float DeltaSeconds) override#

Public Static Functions

static float ComputeHoverForceZ(float Mass, float GravityZ, float CurrentHeight, float VerticalVelocity, float TargetHeight, float TimeToRecover, float DeltaSeconds)#

Vertical hover force: gravity compensation plus the force that brings the vertical velocity to (TargetHeight - CurrentHeight) / TimeToRecover within DeltaSeconds.

Parameters:
  • Mass – Mass of the hoverboard (kg).

  • GravityZ – World gravity along Z (cm/s^2, negative is down).

  • CurrentHeight – Current height above the ground (cm).

  • VerticalVelocity – Current vertical velocity (cm/s).

  • TargetHeight – Desired height above the ground (cm).

  • TimeToRecover – Time in which the target height should be reached (s).

  • DeltaSeconds – Tick duration (s); when not positive only gravity is compensated.

Returns:

Upward force (kg*cm/s^2), never negative.