mirror of
https://github.com/Winded/RagdollMover.git
synced 2025-03-04 03:13:36 -05:00
Move similar snapamount statements to a snapAngles function; quick workaround to snap rotating by 180 degrees
This commit is contained in:
parent
3f47d46cc0
commit
1374f52bc2
@ -654,6 +654,38 @@ do
|
||||
return result
|
||||
end
|
||||
|
||||
local mfmod = math.fmod
|
||||
|
||||
local function snapAngle(localized, startangle, snapamount)
|
||||
local localAng = mfmod(localized.y, 360)
|
||||
if localAng > 181 then localAng = localAng - 360 end
|
||||
if localAng < -181 then localAng = localAng + 360 end
|
||||
|
||||
local localStart = mfmod(startangle.y, 360)
|
||||
if localStart > 181 then localStart = localStart - 360 end
|
||||
if localStart < -181 then localStart = localStart + 360 end
|
||||
|
||||
local diff = mfmod(localStart - localAng, 360)
|
||||
if diff > 181 then diff = diff - 360 end
|
||||
if diff < -181 then diff = diff + 360 end
|
||||
|
||||
-- TODO:
|
||||
-- Workaround to rotating by 180 degrees by removing normalization step
|
||||
-- Still buggy, but allows rotating beyond 180 degrees
|
||||
if snapamount == 180 then
|
||||
diff = mfmod(localStart - localAng, 360)
|
||||
end
|
||||
|
||||
local mathfunc = nil
|
||||
if diff >= 0 then
|
||||
mathfunc = math.floor
|
||||
else
|
||||
mathfunc = math.ceil
|
||||
end
|
||||
|
||||
return startangle.y - (mathfunc(diff / snapamount) * snapamount)
|
||||
end
|
||||
|
||||
function disc:ProcessMovement(_, offang, eyepos, eyeang, ent, bone, ppos, pnorm, movetype, snapamount, startangle, _, nphysangle) -- initially i had a table instead of separate things for initial bone pos and angle, but sync command can't handle tables and i thought implementing a way to handle those would be too much hassle
|
||||
local intersect = self:GetGrabPos(eyepos, eyeang, ppos, pnorm)
|
||||
local localized = self:WorldToLocal(intersect)
|
||||
@ -672,8 +704,6 @@ do
|
||||
axistable[3]:Normalize()
|
||||
axistable[4]:Normalize()
|
||||
|
||||
local mfmod = math.fmod
|
||||
|
||||
if movetype == 1 then
|
||||
local offset = RAGDOLLMOVER[axis.Owner].GizmoOffset
|
||||
local entoffset = vector_origin
|
||||
@ -692,26 +722,7 @@ do
|
||||
|
||||
local rotationangle = localized.y
|
||||
if snapamount ~= 0 then
|
||||
local localAng = mfmod(localized.y, 360)
|
||||
if localAng > 181 then localAng = localAng - 360 end
|
||||
if localAng < -181 then localAng = localAng + 360 end
|
||||
|
||||
local localStart = mfmod(startangle.y, 360)
|
||||
if localStart > 181 then localStart = localStart - 360 end
|
||||
if localStart < -181 then localStart = localStart + 360 end
|
||||
|
||||
local diff = mfmod(localStart - localAng, 360)
|
||||
if diff > 181 then diff = diff - 360 end
|
||||
if diff < -181 then diff = diff + 360 end
|
||||
|
||||
local mathfunc = nil
|
||||
if diff >= 0 then
|
||||
mathfunc = math.floor
|
||||
else
|
||||
mathfunc = math.ceil
|
||||
end
|
||||
|
||||
rotationangle = startangle.y - (mathfunc(diff / snapamount) * snapamount)
|
||||
rotationangle = snapAngle(localized, startangle, snapamount)
|
||||
end
|
||||
|
||||
local pos = self:GetPos()
|
||||
@ -826,26 +837,7 @@ do
|
||||
|
||||
local rotationangle = localized.y
|
||||
if snapamount ~= 0 then
|
||||
local localAng = mfmod(localized.y, 360)
|
||||
if localAng > 181 then localAng = localAng - 360 end
|
||||
if localAng < -181 then localAng = localAng + 360 end
|
||||
|
||||
local localStart = mfmod(startangle.y, 360)
|
||||
if localStart > 181 then localStart = localStart - 360 end
|
||||
if localStart < -181 then localStart = localStart + 360 end
|
||||
|
||||
local diff = mfmod(localStart - localAng, 360)
|
||||
if diff > 181 then diff = diff - 360 end
|
||||
if diff < -181 then diff = diff + 360 end
|
||||
|
||||
local mathfunc = nil
|
||||
if diff >= 0 then
|
||||
mathfunc = math.floor
|
||||
else
|
||||
mathfunc = math.ceil
|
||||
end
|
||||
|
||||
rotationangle = startangle.y - (mathfunc(diff / snapamount) * snapamount)
|
||||
rotationangle = snapAngle(localized, startangle, snapamount)
|
||||
end
|
||||
|
||||
local pos = self:GetPos()
|
||||
|
Loading…
Reference in New Issue
Block a user