This content originally appeared on DEV Community and was authored by Maciej Sawicki
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.
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.
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.
Update Charge
updates the Charge
variable and calls events: Battery Charge Changed
or when it drops to zero Battery Charge Depleted
.
This content originally appeared on DEV Community and was authored by Maciej Sawicki

Maciej Sawicki | Sciencx (2024-07-03T22:06:20+00:00) [Game of Purpose] Day 46 – Simple Battery System. Retrieved from https://www.scien.cx/2024/07/03/game-of-purpose-day-46-simple-battery-system/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.