local v=script:FindFirstAncestor("\076\105\109\098\067\104\097\105\110")local d=require(v.BaseRedirect)local q=script:FindFirstAncestor("\070\097\098\114\105\107\067\111\110\115\116\114\097\105\110\116")local R=require(q)local m=d.newExtends("\082\105\103\105\100\067\111\110\115\116\114\097\105\110\116",R)function m.new(v)local d if not v:isA("\076\105\109\098\067\104\097\105\110")then d=m:super(v)else d=m:super()d.LimbChain=v end return d end function m.ConstrainLimbVector(d,v)local q=v.JointPosition local R=v.LimbVector local m=v.LimbLength local B=v.Index if d.Part~=nil then d:UpdateAxis()return d.CenterAxis.Unit*m else local v=Vector3.new(.01,.01,.01)return((d.LimbChain:GetOriginalLimbDirection(B)).Unit+v)*m end end return m


-- Initialize Object Class
local Package = script:FindFirstAncestor("LimbChain")
local Object = require(Package.BaseRedirect)

--Require the FabrikConstraint for Inheritance
local FabrikConstraintPointer = script:FindFirstAncestor("FabrikConstraint")
local FabrikConstraint = require(FabrikConstraintPointer)

--Initialize the Self Class
local RigidConstraint = Object.newExtends("RigidConstraint",FabrikConstraint)

--[[--------------------------------------------------------
    Create the constraint
    Parameters:
]]
function RigidConstraint.new(PartOrLimbChain)
    local obj

    --[[
        Detects if parameter 1 is a limb chain object, if it is then it constraints to the original limb position
        
    ]]
    if  not PartOrLimbChain:isA("LimbChain") then
    
    obj = RigidConstraint:super(PartOrLimbChain)

    else
        
    obj = RigidConstraint:super()
   
    obj.LimbChain = PartOrLimbChain

    end
    
	return obj
end

--[[
    Constraints the limbVector like a rigid joint
    It doesn't move and the joint points in the part's current direction
    or it points in the motor6ds original direction
    returns a new limbvector vector 3 at full length
]]
function RigidConstraint:ConstrainLimbVector(currentVectorInformation)
    
    local jointPosition = currentVectorInformation.JointPosition
    local limbVector = currentVectorInformation.LimbVector
    local limbLength = currentVectorInformation.LimbLength
    local index = currentVectorInformation.Index

    --Checks if there is a part to set the constraint axis to
    if self.Part ~=nil then

        --Get the constraining part current axis
        self:UpdateAxis()

        --Make it point in the part's center axis
        return self.CenterAxis.Unit*limbLength

    else
        --offset to prevent nan or 0,0,0
        local minorOffset = Vector3.new(0.01,0.01,0.01)
        --Else get the original limbvector
        return (self.LimbChain:GetOriginalLimbDirection(index).Unit+minorOffset)*limbLength

    end
end


return RigidConstraint