function Rest()
    local world = TransformToParentTransform(GetCameraTransform(), Keyframes.Deploy)
    AutoSM_Set(SM.pos, world.pos)
    AutoSM_Set(SM.rot, world.rot)
    Mem.Last_keyframe_id = 'Default'

    --- Resetting
    Mem.Pulled_Trigger = false
    Mem.Throwing_Gun = false
    Mem.Extra_Trigger_Pulls = 0

    for key, _ in pairs(Mem.Time) do
        Mem.Time[key] = -1 / 0
    end
end

function IsShapesTouchingShape(shapes, shape)
    for _, s in pairs(shapes) do
        if IsShapeTouching(s, shape) then return true end
    end
    return false
end

function Sparks(origin, dir, spread, followthrough, count, color)
    dir = VecNormalize(dir)

    ParticleReset()
    ParticleType('plain')
    ParticleCollide(0, 1, 'constant', 0.05)
    ParticleRadius(0.045, 0)
    ParticleDrag(0.65)

    ParticleTile(6)
    ParticleColor(unpack(color))
    ParticleEmissive(1)
    ParticleStretch(20, 1, 'cosine')

    for i = 1, count do
        local _spread = AutoSigmoid(nil, spread, -5, 1) * 2
        local _followthrough = AutoSigmoid(nil, followthrough, -5, 1) * 2

        local rnd = VecScale(AutoVecRnd(1), _spread)
        local force = VecAdd(VecScale(dir, _followthrough), rnd)
        SpawnParticle(origin, force, math.random() * 0.2 + 0.075)
    end

    PointLight(origin, color[1], color[2], color[3], (spread + followthrough) * 0.08)
end

function ProjectileTrail(origin, dir, color)
    ParticleReset()
    ParticleType('plain')
    ParticleCollide(0, 1, 'constant', 0.05)
    ParticleRadius(0.045, 0)
    ParticleDrag(0.65)

    ParticleTile(6)
    ParticleColor(unpack(color))
    ParticleEmissive(1)
    ParticleStretch(20, 1, 'cosine')

    SpawnParticle(origin, VecScale(dir, 2.5), 0.125)
end

function OverheatParticles(origin, velocity, strength)
    ParticleReset()
    ParticleType('plain')
    ParticleCollide(0, 1, 'constant', 0.05)
    ParticleRadius(0.075 * strength, 0.7 * strength)
    ParticleDrag(0.4)

    ParticleTile(0)
    ParticleColor(0.5, 0.5, 0.5, 0.1, 0.1, 0.1)

    SpawnParticle(origin, velocity, (0.4 + 0.8 * math.random()) * strength)
end