DEV Community

Maciej Sawicki
Maciej Sawicki

Posted on

[Game of Purpose] Day 46 - Simple Battery System

Today I implemented a simple battery system. It has a status indicator in the top right corner. It has a configurable rate of depletion and automatically turns the engine off when it runs out of power.

A 3D rendered scene showing a drone on a grid-patterned platform, with a clear sky and simple geometric structures in the background. The interface indicates

First I create a BPC_Drone_Battery component. It has an event DrainTick called every TickEvery amount of time and calls a Drain Charge function.

Image description

Drain Charge function simply takes Drain Per Tick away from a total charge and calls Update Charge. It does nothing when the battery is off.

Image description

Update Charge updates the Charge variable and calls events: Battery Charge Changed or when it drops to zero Battery Charge Depleted.

Image description

Top comments (0)