Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- functions = {}
- clients = {}
- spring = {}
- renderRate = 120
- --// Spring Class Setup
- do
- local e = 2.7182818284590452353602875 -- euler's number
- function spring.new(position, velocity, target)
- local self = setmetatable({}, {__index = spring})
- self.position = position
- self.velocity = velocity
- self.target = target
- self.k = 1
- self.d = 1 -- friction constant
- return self
- end
- function spring:update()
- local x = self.target - self.position
- local f = x * self.k
- self.velocity = (self.velocity * (1 - self.d)) + f
- self.position = self.position + self.velocity
- end
- end
- -- // Modules
- local chain = require(game.ReplicatedStorage.FABRIK)
- --
- local Character = script.Parent
- local RightShoulderBase0, RightShoulderBase1 = Character.RightUpperArm.RightShoulder.C0, Character.RightUpperArm.RightShoulder.C1
- local LeftShoulderBase0, LeftShoulderBase1 = Character.LeftUpperArm.LeftShoulder.C0, Character.LeftUpperArm.LeftShoulder.C1
- local ElbowBase0, ElbowBase1 = Character.RightLowerArm.RightElbow.C0, Character.RightLowerArm.RightElbow.C1
- Character.RightUpperArm.RightShoulder.C0 = RightShoulderBase0 --* CFrame.Angles(math.rad(45),0,0)
- Character.RightUpperArm.RightShoulder.C1 = RightShoulderBase1
- Character.RightLowerArm.RightElbow.C0 = ElbowBase0 --* CFrame.Angles(math.rad(-45),0,0)
- Character.RightLowerArm.RightElbow.C1 = ElbowBase1
- character = {}
- local function projectVector(a, b)
- return a - a:Dot(b.unit)*b
- end
- local function vectorToAngle(v0,v1,plane)
- v0,v1 = projectVector(v0.unit, plane), projectVector(v1.unit, plane)
- local angle = math.acos(v0:Dot(v1))
- local cross = v0:Cross(v1)
- if plane:Dot(cross) < 0 then
- angle = -angle
- end
- return angle
- end
- local rightArm = chain.new({
- Vector3.new(0,0,0), --Shoulder
- Vector3.new(0,-0.9,0), --Elbow
- Vector3.new(0,-2,0) --Grip
- },
- Vector3.new(0,-2,0)
- )
- local leftArm = chain.new({
- Vector3.new(0,0,0), --Shoulder
- Vector3.new(0,-0.9,0), --Elbow
- Vector3.new(0,-2,0) --Grip
- },
- Vector3.new(0,-2,0)
- )
- wait(2)
- local completed = false
- local lastUpdate = 0
- local part = Instance.new("Part",game.Workspace)
- part.Size = Vector3.new(.2,.2,.2)
- part.Anchored = true
- local parts = {}
- game:GetService('RunService').RenderStepped:connect(function()
- if tick() > lastUpdate + 1/renderRate then
- lastUpdate = tick()
- local ShoulderCF = CFrame.new(Character.UpperTorso.RightShoulderRigAttachment.WorldPosition, Character.UpperTorso.RightShoulderRigAttachment.WorldPosition + Character.UpperTorso.CFrame.lookVector)
- local LeftShoulderCF = CFrame.new(Character.UpperTorso.LeftShoulderRigAttachment.WorldPosition, Character.UpperTorso.LeftShoulderRigAttachment.WorldPosition + Character.UpperTorso.CFrame.lookVector)
- local target = ShoulderCF:toObjectSpace(Character:FindFirstChild('Weapon').CFrame).p
- rightArm.target = target
- leftArm.target = LeftShoulderCF:toObjectSpace(Character:FindFirstChild('Weapon').CFrame * CFrame.new(0,0,-.8)).p --+Right/-Left, +Up/-Down, +Back/-Forward
- rightArm:solve()
- leftArm:solve()
- --part.CFrame = ShoulderCF * CFrame.new(rightArm.joints[3])
- --// Right Arm
- local Vectors = {
- ShoulderBase = Vector3.new(0,-1,0),
- ShoulderFace = Vector3.new(0,0,-1),
- ShoulderToElbow = (rightArm.joints[2] - rightArm.joints[1]).unit,
- ElbowBase = (rightArm.joints[2] - rightArm.joints[1]).unit,
- --ElbowFace =
- ElbowToGrip = (rightArm.joints[3] - rightArm.joints[2]).unit
- }
- local Normals = {
- Right = Vector3.FromNormalId(Enum.NormalId.Right),
- Up = Vector3.FromNormalId(Enum.NormalId.Top),
- Front = Vector3.FromNormalId(Enum.NormalId.Front),
- }
- local RightShoulderX = vectorToAngle(Vectors.ShoulderBase, Vectors.ShoulderToElbow, Normals.Front)
- local RightShoulderY = vectorToAngle(Vectors.ShoulderFace, Vectors.ShoulderToElbow, Normals.Up)
- local RightElbowX = vectorToAngle(Vectors.ElbowBase, Vectors.ElbowToGrip, Normals.Front)
- local RightElbowY = vectorToAngle(Vectors.ShoulderFace, Vectors.ElbowToGrip, Normals.Up)
- print(math.deg(RightElbowX),math.deg(RightShoulderY))
- Character.RightUpperArm.RightShoulder.C0 = RightShoulderBase0 * CFrame.Angles(RightShoulderX, RightElbowY, -RightShoulderY) --ShoulderZ, ShoulderX), 1/20)
- Character.RightLowerArm.RightElbow.C0 = ElbowBase0 * CFrame.Angles(RightElbowX,0,0)
- for i,v in ipairs(parts) do
- v:Destroy()
- end
- for i,v in ipairs(rightArm.joints) do
- local part = Instance.new("Part",game.Workspace)
- part.Size = Vector3.new(.2,.2,.2)
- part.Anchored = true
- part.CFrame = ShoulderCF * CFrame.new(v)
- part.CanCollide = false
- table.insert(parts,part)
- end
- --Character.RightLowerArm.RightElbow.C0 = ElbowBase0 * CFrame.Angles(RightElbowX,0,0)
- --
- -- --// Left Arm
- -- local LeftShoulderX = vectorToAngle((Vector3.new(0,-1,0) - leftArm.joints[1]).unit, (leftArm.joints[2] - leftArm.joints[1]).unit)
- -- local LeftShoulderY = vectorToAngle((Vector3.new(1,0,0) - leftArm.joints[1]).unit, (leftArm.joints[2] - leftArm.joints[1]).unit)
- --
- -- local LeftElbowX = vectorToAngle((leftArm.joints[2] - leftArm.joints[1]).unit, (leftArm.joints[3] - leftArm.joints[2]).unit)
- -- local LeftElbowY = vectorToAngle((Vector3.new(-1,0,0)).unit, (leftArm.joints[2] - leftArm.joints[1]).unit)
- -- print(math.deg(LeftElbowY))
- -- Character.LeftUpperArm.LeftShoulder.C0 = LeftShoulderBase0 * CFrame.Angles(LeftShoulderX, LeftShoulderY, LeftElbowY) --ShoulderZ, ShoulderX), 1/20)
- -- Character.LeftLowerArm.LeftElbow.C0 = ElbowBase0 * CFrame.Angles(LeftElbowX,0,0)
- else
- print("Didn't render")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement