Module:BulletGravityMultiplier
Jump to navigation
Jump to search
Documentation for this module may be created at Module:BulletGravityMultiplier/doc
local p = {}
-- Convert ballisticDrop to bulletGravityMultiplier
function p.convert_drop(frame)
local range = tonumber(frame.args.range) or 0
local ballistic_travel = tonumber(frame.args.travel) or 10
local ballistic_steps = tonumber(frame.args.steps) or (range / ballistic_travel)
local ballistic_drop = tonumber(frame.args.drop)
local bullet_gravity_multiplier = 4
if ballistic_drop then -- Has ballisticDrop been specified?
if ballistic_drop < 0.000001 then -- Is ballisticDrop a valid value?
bullet_gravity_multiplier = 0
else
local num1 = 0
local right = {x = 1.0, y = 0.0} -- Create a Vector2.right
local length
for l = 1, ballistic_steps do
num1 = num1 + right.y * ballistic_travel
right.y = right.y - ballistic_drop
-- Normalize the vector...
length = math.sqrt( math.pow(right.x, 2) + math.pow(right.y, 2) ) -- Calculate length
right.x = right.x / length -- Normalize x value
right.y = right.y / length -- Normalize y value
end
-- Finish calculating bulletGravityMultiplier
local num2 = ballistic_steps * 0.02
local num3 = 2 * num1 / (num2 * num2)
bullet_gravity_multiplier = num3 / -9.81
end
end
-- Return the calculated value
return bullet_gravity_multiplier
end
return p