Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local forwardV3 = Vector3.new(0,0,-1)
- local acos = math.acos
- local fromAxisAngle = CFrame.fromAxisAngle
- local max = math.max
- local min = math.min
- local cfNew = CFrame.new
- local cfAngles = CFrame.Angles
- local pi = math.pi
- local runS = game:GetService("RunService")
- local UIService = game:GetService("UserInputService")
- local TweenService = game:GetService("TweenService")
- local RS = runS.RenderStepped
- local Cam = workspace.CurrentCamera
- local Player = game.Players.LocalPlayer
- local Char = script.Parent
- local Hum = Char.Humanoid
- local Root = Char.HumanoidRootPart
- local Active = false
- local gyro = Instance.new("BodyGyro", Root)
- local Mouse = Player:GetMouse()
- local CurrentlyInteractable = nil
- local InteractBtn = script:WaitForChild'Button'
- local IgnoreList = {
- ["RightFoot"] = true,
- ["RightLowerLeg"] = true,
- ["RightUpperLeg"] = true,
- ["LeftFoot"] = true,
- ["LeftLowerLeg"] = true,
- ["LeftUpperLeg"] = true,
- ["UpperTorso"] = true,
- ["LowerTorso"] = true,
- ["Head"] = true
- }
- print("Loading Appearence")
- wait()
- do--bodyColors
- local SkinColor = Color3.fromRGB(199, 172, 120)
- local ShirtColor = Color3.fromRGB(127, 142, 100)
- local BC = Char:WaitForChild'Body Colors'
- BC.HeadColor3 = SkinColor
- BC.LeftArmColor3 = SkinColor
- BC.LeftLegColor3 = SkinColor
- BC.RightArmColor3 = SkinColor
- BC.RightLegColor3 = SkinColor
- BC.TorsoColor3 = ShirtColor
- end
- do--clothing
- Char.Pants.PantsTemplate = "rbxassetid://2189256030"
- end
- Hum:WaitForChild'BodyDepthScale'.Value = 0.7
- Hum:WaitForChild'BodyWidthScale'.Value = 0.7
- Hum:WaitForChild'BodyHeightScale'.Value = 1
- Hum:WaitForChild'HeadScale'.Value = 0.8
- for i, v in pairs(Char:GetChildren()) do
- if not IgnoreList[v.Name] and v:IsA("MeshPart") then
- v.Transparency = 1
- end
- end
- Mouse.Icon = 'rbxassetid://120192974'
- local IKLimbs = {
- ["RightArm"] = {
- ["ShoulderW"] = nil,
- ["ElbowW"] = nil,
- ["ULength"] = 0.95,
- ["LLength"] = 0.95,
- ["Offset"] = CFrame.new(1.05,0.8,0),
- ["Target"] = Char["RightHand"],
- ["TargetOffset"] = CFrame.new(0,-Char["RightHand"].Size/2,0),
- ["OffsetAngle"] = 0
- },
- ["LeftArm"] = {
- ["ShoulderW"] = nil,
- ["ElbowW"] = nil,
- ["ULength"] = 0.95,
- ["LLength"] = 0.95,
- ["Offset"] = CFrame.new(-1.05,0.8,0),
- ["Target"] = Char["LeftHand"],
- ["TargetOffset"] = CFrame.new(0,-Char["LeftHand"].Size/2,0),
- ["OffsetAngle"] = 0
- },
- --[[["RightLeg"] = {
- ["ShoulderW"] = nil,
- ["ElbowW"] = nil,
- ["ULength"] = 1,
- ["LLength"] = 1,
- ["Offset"] = CFrame.new(0.5,-1,0),
- ["Target"] = Char["RightFoot"],
- ["TargetOffset"] = CFrame.new(0.1,Char["RightFoot"].Size/2,0),
- ["OffsetAngle"] = 175
- },
- ["LeftLeg"] = {
- ["ShoulderW"] = nil,
- ["ElbowW"] = nil,
- ["ULength"] = 1,
- ["LLength"] = 1,
- ["Offset"] = CFrame.new(-0.5,-1,0),
- ["Target"] = Char["LeftFoot"],
- ["TargetOffset"] = CFrame.new(-0.1,-Char["LeftFoot"].Size/2,0),
- ["OffsetAngle"] = -175
- },]]
- }
- local InteractableAnimations = {
- ["Locker"] = function(locker)
- local Door = locker:FindFirstChild'Door'
- local Handle = Door:FindFirstChild'Handle'
- local rightArm = IKLimbs["RightArm"]
- local originalTarget = rightArm.Target
- local originalTargetOffset = rightArm.TargetOffset
- local Motor = Door:FindFirstChild'Motor'
- Motor.AngularVelocity = -10
- Root.Anchored = true
- rightArm.TargetOffset = CFrame.new(0,0,0)
- rightArm.Target = Handle
- Door.CanCollide = false
- wait(1)
- Door.CanCollide = true
- rightArm.Target = originalTarget
- rightArm.TargetOffset = originalTargetOffset
- Root.Anchored = false
- Motor.AngularVelocity = 0
- return
- end
- }
- local function solveIK(originCF, targetPos, l1, l2)
- local localized = originCF:pointToObjectSpace(targetPos)
- local localizedUnit = localized.unit
- local l3 = localized.magnitude
- local axis = forwardV3:Cross(localizedUnit)
- local angle = acos(-localizedUnit.Z)
- local planeCF = originCF * fromAxisAngle(axis, angle)
- if l3 < max(l2, l1) - min(l2, l1) then
- return planeCF * cfNew(0, 0, max(l2, l1) - min(l2, l1) - l3), -pi/2, pi
- elseif l3 > l1 + l2 then
- return planeCF * cfNew(0, 0, l1 + l2 - l3), pi/2, 0
- else
- local a1 = -acos((-(l2 * l2) + (l1 * l1) + (l3 * l3)) / (2 * l1 * l3))
- local a2 = acos(((l2 * l2) - (l1 * l1) + (l3 * l3)) / (2 * l2 * l3))
- return planeCF, a1 + pi/2, a2 - a1
- end
- end
- do
- for key, value in next, IKLimbs do
- local ULength = value.ULength
- local LLength = value.LLength
- local Offset = value.Offset
- local UpperC0 = value.UpperC0
- local LowerC0 = value.LowerC0
- local Torso = Char.UpperTorso
- local bColors = Char:WaitForChild("Body Colors")
- local UArm = Instance.new("Part",Char)
- UArm.Color = bColors.TorsoColor3
- UArm.TopSurface = "Smooth"
- UArm.BottomSurface = "Smooth"
- UArm.Size = Vector3.new(0.68,ULength,0.68)
- UArm.CanCollide = false
- local ShoulderW = Instance.new("Weld", UArm)
- ShoulderW.Part0 = Torso
- ShoulderW.Part1 = UArm
- value.ShoulderW = ShoulderW
- local SMesh = Instance.new("SpecialMesh", UArm)
- SMesh.MeshId = "rbxasset://fonts/leftarm.mesh"
- SMesh.Scale = Vector3.new(0.68,0.5,0.68)
- local UArmShirt = script.Arm:Clone()
- UArmShirt.PrimaryPart.MainWeld.Part0 = UArm
- UArmShirt.Parent = UArm
- local ElbowSkin = Instance.new("Part",Char)
- ElbowSkin.Color = bColors.RightArmColor3
- ElbowSkin.TopSurface = "Smooth"
- ElbowSkin.BottomSurface = "Smooth"
- ElbowSkin.Size = Vector3.new(0.68,0.68,0.68)
- ElbowSkin.CanCollide = false
- ElbowSkin.Shape = "Cylinder"
- local ElbowSkinW = Instance.new("Weld", UArm)
- ElbowSkinW.C0 = cfNew(0,-ULength/2,0)*cfAngles(0,0,math.rad(90))
- ElbowSkinW.Part0 = UArm
- ElbowSkinW.Part1 = ElbowSkin
- local SMesh1 = Instance.new("SpecialMesh", ElbowSkin)
- SMesh1.MeshId = "rbxassetid://2044091701"
- SMesh1.Scale = Vector3.new(0.337,0.337,0.337)
- local LArm = Instance.new("Part",Char)
- LArm.Color = bColors.RightArmColor3
- LArm.TopSurface = "Smooth"
- LArm.BottomSurface = "Smooth"
- LArm.Size = Vector3.new(0.68,LLength,0.68)
- LArm.CanCollide = false
- local ElbowW = Instance.new("Weld", LArm)
- ElbowW.Part0 = UArm
- ElbowW.Part1 = LArm
- value.ElbowW = ElbowW
- local SMesh1 = Instance.new("SpecialMesh", LArm)
- SMesh1.MeshId = "rbxasset://fonts/leftarm.mesh"
- SMesh1.Scale = Vector3.new(0.68,0.5,0.68)
- end
- end
- UIService.InputBegan:Connect(function(input, Occupied)
- if not Active and not Occupied and input.KeyCode == Enum.KeyCode.F then
- if CurrentlyInteractable then
- Active = true
- InteractableAnimations[CurrentlyInteractable.Name](CurrentlyInteractable)
- Active = false
- end
- end
- end)
- while RS:wait() do
- CurrentlyInteractable = nil
- for i,v in pairs(workspace:FindFirstChild'InteractableObjects':GetChildren()) do
- local Magnitude = (v.PrimaryPart.Position - Mouse.Hit.p).magnitude
- local Magnitude2 = (v.PrimaryPart.Position - Root.Position).magnitude
- if Magnitude < 1 and Magnitude2 < 3 then
- InteractBtn.Enabled = true
- InteractBtn.Parent = v.PrimaryPart
- CurrentlyInteractable = v
- end
- if CurrentlyInteractable then
- local CurCF = CurrentlyInteractable:GetPrimaryPartCFrame()
- if Magnitude < (CurCF.p - Mouse.Hit.p).magnitude and Magnitude2 < (CurCF.p - Root.Position).magnitude then
- InteractBtn.Enabled = true
- InteractBtn.Parent = v.PrimaryPart
- CurrentlyInteractable = v
- end
- end
- end
- if not CurrentlyInteractable then
- InteractBtn.Parent = script
- InteractBtn.Enabled = false
- end
- for key, value in next, IKLimbs do
- local OffsetAngle = value.OffsetAngle
- local Torso = Char.UpperTorso
- local TargetOffset = value.TargetOffset
- local shoulderCF = Torso.CFrame * value.Offset * cfAngles(0,0,math.rad(OffsetAngle))
- local TARGET_POS = value.Target.CFrame*TargetOffset.p
- local ShoulderW = value.ShoulderW
- local ULength = value.ULength
- local LLength = value.LLength
- local ElbowW = value.ElbowW
- local plane, shoulderAngle, elbowAngle = solveIK(shoulderCF, TARGET_POS, ULength, LLength)
- ShoulderW.C0 = Torso.CFrame:toObjectSpace(plane) * cfAngles(shoulderAngle,0,0) * cfNew(0,-ULength/2,0)
- ElbowW.C0 = cfNew(0,0,0) * cfNew(0,-ULength/2,0) * cfAngles(elbowAngle,0,0) * cfNew(0,-LLength/2,0)
- --Root.CFrame = CFrame.new(Root.Position, Vector3.new(Mouse.Hit.p.X, Root.Position.Y, Mouse.Hit.p.Z))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement