dofile_once( "mods/spellbound_bundle/files/scripts/utils.lua");
local entity = GetUpdatedEntityID();

local velocity = EntityGetFirstComponentIncludingDisabled( entity, "VelocityComponent" );
if velocity ~= nil then
    local vx,vy = ComponentGetValue2( velocity, "mVelocity", vx, vy );
    local magnitude = math.sqrt( vx * vx + vy * vy );
    local frames = GameGetFrameNum() - (EntityGetVariable( entity, "gkbrkn_chaotic_burst_frame", "int" ) or GameGetFrameNum());
    local scale = math.random() * math.pow( magnitude, 0.6 ) / 60 * math.min( 1, frames * 0.20 );
    local angle = math.atan2( vy, vx ) + ( math.random() - 0.5 ) * math.pi * scale;

    ComponentSetValue2( velocity, "mVelocity", math.cos( angle ) * magnitude, math.sin( angle ) * magnitude );
end

if EntityGetVariable( entity, "gkbrkn_chaotic_burst_frame", "int" ) == nil then
    EntitySetVariable( entity, "gkbrkn_chaotic_burst_frame", "int", GameGetFrameNum() );
end