Skip to content

Commit

Permalink
Fix issues with gearbox -> prop connection
Browse files Browse the repository at this point in the history
  • Loading branch information
marchc1 committed Feb 27, 2025
1 parent c540b72 commit 9785ef5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 18 additions & 2 deletions lua/acf/core/utilities/util_sh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,27 @@ do
--- Determines the angle between a driveshaft input and output.
--- A return value of zero means that both entities are facing each other perfectly.
function ACF.DetermineDriveshaftAngle(InputEntity, Input, OutputEntity, Output)
local IP, InputWorldDir = Input:ApplyTo(InputEntity)
if Output == nil then
local Link = OutputEntity

Output = ACF.LocalPlane(Link.Origin, Link.Axis)
OutputEntity = Link.Source
end

local OP, OutputWorldDir = Output:ApplyTo(OutputEntity)
debugoverlay.Line(OP, OP + (OutputWorldDir * 200), 2, Color(20, 255, 20))

if Input == nil then
if InputEntity:GetClass() == "prop_physics" then
local Degrees = (1 - (InputEntity:GetPos() - OP):GetNormalized():Dot(OutputWorldDir)) * 180
return Degrees
else
error("Input == nil AND InputEntity != prop_physics!")
end
end

local IP, InputWorldDir = Input:ApplyTo(InputEntity)
debugoverlay.Line(IP, IP + (InputWorldDir * 200), 2, Color(255, 20, 20))
debugoverlay.Line(OP, OP + (OutputWorldDir * 200), 2, Color(20, 255, 20))

local OutToIn = 1 - (OP - IP):GetNormalized():Dot(InputWorldDir)
local InToOut = 1 - (IP - OP):GetNormalized():Dot(OutputWorldDir)
Expand Down
6 changes: 2 additions & 4 deletions lua/entities/acf_gearbox/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ do -- Spawn and Update functions -----------------------
continue
end

if ACF.IsDriveshaftAngleExcessive(Ent, Ent.In, Link, Link.Out) then
if ACF.IsDriveshaftAngleExcessive(Ent, Ent.In, Link) then
Entity:Unlink(Ent)
end
end
Expand Down Expand Up @@ -609,13 +609,11 @@ do -- Linking ------------------------------------------
local OutPosWorld = Entity:LocalToWorld(OutPos)
if ACF.IsDriveshaftAngleExcessive(Target, Target.In, Entity, Plane) then return end

local Phys = Target:GetPhysicsObject()
local Axis = Phys:WorldToLocalVector(Entity:GetRight())
local Link = MobilityObj.Link(Entity, Target)

Link:SetOrigin(OutPos)
Link:SetTargetPos(InPos)
Link:SetAxis(Axis)
Link:SetAxis(Plane.Dir)
Link.Side = Side
Link.RopeLen = (OutPosWorld - InPosWorld):Length()

Expand Down

0 comments on commit 9785ef5

Please sign in to comment.