Skip to content

Commit

Permalink
Merge pull request #442 from yoseij/patch-2
Browse files Browse the repository at this point in the history
Update init.lua to solve weight inaccuracy
  • Loading branch information
marchc1 authored Dec 25, 2024
2 parents 3879455 + ba35c0c commit 8176e1b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lua/entities/acf_gun/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ local function UpdateTotalAmmo(Entity)
end

do -- Spawn and Update functions --------------------------------
local ModelData = ACF.ModelData
local WireIO = Utilities.WireIO
local Entities = Classes.Entities
local Weapons = Classes.Weapons
Expand Down Expand Up @@ -114,14 +113,13 @@ do -- Spawn and Update functions --------------------------------
return Result
end

local function GetMass(Model, PhysObj, Class, Weapon)
if Weapon then return Weapon.Mass end
local function GetMass(Caliber, Class, Weapon)
if Weapon then return Weapon.Mass end

local Volume = PhysObj:GetVolume()
local Factor = Volume / ModelData.GetModelVolume(Model)
local Factor = Caliber / Class.Caliber.Base

return math.Round(Class.Mass * Factor)
end
return math.Round(Class.Mass * Factor ^ 3) -- 3d space so scaling has a cubing effect
end

local function UpdateWeapon(Entity, Data, Class, Weapon)
local Model = Weapon and Weapon.Model or Class.Model
Expand Down Expand Up @@ -190,7 +188,7 @@ do -- Spawn and Update functions --------------------------------
local PhysObj = Entity.ACF.PhysObj

if IsValid(PhysObj) then
local Mass = GetMass(Model, PhysObj, Class, Weapon)
local Mass = GetMass(Caliber, Class, Weapon)

Contraption.SetMass(Entity, Mass)
end
Expand Down

0 comments on commit 8176e1b

Please sign in to comment.