35 lines
1.6 KiB
Luau
35 lines
1.6 KiB
Luau
--!strict
|
|
local RifleSpray = {PreciseShots = 4}
|
|
|
|
-- The rifle climbs, sweeps left, crosses right, then settles into a smaller sweep.
|
|
-- X is right on screen and Y is up. Scale each pair by the configured spray angle.
|
|
local pattern = {
|
|
Vector2.new(.08, 1), Vector2.new(.11, 1), Vector2.new(.10, 1), Vector2.new(.04, 1),
|
|
Vector2.new(-.03, 1), Vector2.new(-.14, 1), Vector2.new(-.24, 1), Vector2.new(-.36, .98),
|
|
Vector2.new(-.50, .96), Vector2.new(-.65, .92), Vector2.new(-.74, .88), Vector2.new(-.78, .85),
|
|
Vector2.new(-.70, .83), Vector2.new(-.58, .81), Vector2.new(-.36, .79), Vector2.new(-.05, .77),
|
|
Vector2.new(.24, .75), Vector2.new(.48, .73), Vector2.new(.67, .72), Vector2.new(.73, .71),
|
|
Vector2.new(.61, .70), Vector2.new(.42, .68), Vector2.new(.17, .66), Vector2.new(-.12, .67),
|
|
Vector2.new(-.36, .69), Vector2.new(-.54, .71),
|
|
}
|
|
local tailStart = 19
|
|
|
|
function RifleSpray.resetDelay(interval: number, recovery: number): number
|
|
return math.max(interval * 1.75, math.clamp(2 / math.max(recovery, .1), .24, .95))
|
|
end
|
|
|
|
function RifleSpray.offset(shot: number, base: number, growth: number, limit: number): Vector2
|
|
local index = shot - RifleSpray.PreciseShots
|
|
if index <= 0 then return Vector2.zero end
|
|
local angle = math.clamp(base + math.min(index * math.max(growth, 0), math.max(limit, 0)), 0, 15)
|
|
if index > #pattern then
|
|
-- Magazines larger than 30 retain the final sweep without jumping back to the centre.
|
|
local width = #pattern - tailStart
|
|
local phase = (index - tailStart) % (width * 2)
|
|
index = tailStart + math.min(phase, width * 2 - phase)
|
|
end
|
|
return pattern[index] * (angle / 3)
|
|
end
|
|
|
|
return table.freeze(RifleSpray)
|