SHARE
TWEET

Untitled

a guest Jul 20th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local forwardV3 = Vector3.new(0,0,-1)
  2. local acos = math.acos
  3. local fromAxisAngle = CFrame.fromAxisAngle
  4. local max = math.max
  5. local min = math.min
  6. local cfNew = CFrame.new
  7. local cfAngles = CFrame.Angles
  8. local pi = math.pi
  9. local runS = game:GetService("RunService")
  10. local UIService = game:GetService("UserInputService")
  11. local TweenService = game:GetService("TweenService")
  12. local RS = runS.RenderStepped
  13. local Cam = workspace.CurrentCamera
  14. local Player = game.Players.LocalPlayer
  15. local Char = script.Parent
  16. local Hum = Char.Humanoid
  17. local Root = Char.HumanoidRootPart
  18. local Active = false
  19. local gyro = Instance.new("BodyGyro", Root)
  20. local Mouse = Player:GetMouse()
  21. local CurrentlyInteractable = nil
  22. local InteractBtn = script:WaitForChild'Button'
  23.  
  24. local IgnoreList = {
  25.     ["RightFoot"] = true,
  26.     ["RightLowerLeg"] = true,
  27.     ["RightUpperLeg"] = true,
  28.     ["LeftFoot"] = true,
  29.     ["LeftLowerLeg"] = true,
  30.     ["LeftUpperLeg"] = true,
  31.     ["UpperTorso"] = true,
  32.     ["LowerTorso"] = true,
  33.     ["Head"] = true
  34. }
  35.  
  36. print("Loading Appearence")
  37. wait()
  38. do--bodyColors
  39.     local SkinColor = Color3.fromRGB(199, 172, 120)
  40.     local ShirtColor = Color3.fromRGB(127, 142, 100)
  41.     local BC = Char:WaitForChild'Body Colors'
  42.     BC.HeadColor3 = SkinColor
  43.     BC.LeftArmColor3 = SkinColor
  44.     BC.LeftLegColor3 = SkinColor
  45.     BC.RightArmColor3 = SkinColor
  46.     BC.RightLegColor3 = SkinColor
  47.     BC.TorsoColor3 = ShirtColor
  48. end
  49.  
  50. do--clothing
  51.     Char.Pants.PantsTemplate = "rbxassetid://2189256030"
  52. end
  53.  
  54. Hum:WaitForChild'BodyDepthScale'.Value = 0.7
  55. Hum:WaitForChild'BodyWidthScale'.Value = 0.7
  56. Hum:WaitForChild'BodyHeightScale'.Value = 1
  57. Hum:WaitForChild'HeadScale'.Value = 0.8
  58.  
  59. for i, v in pairs(Char:GetChildren()) do
  60.     if not IgnoreList[v.Name] and v:IsA("MeshPart") then
  61.         v.Transparency = 1
  62.     end
  63. end
  64.  
  65. Mouse.Icon = 'rbxassetid://120192974'
  66.  
  67. local IKLimbs = {
  68.     ["RightArm"] = {
  69.         ["ShoulderW"] = nil,
  70.         ["ElbowW"] = nil,
  71.         ["ULength"] = 0.95,
  72.         ["LLength"] = 0.95,
  73.         ["Offset"] = CFrame.new(1.05,0.8,0),
  74.         ["Target"] = Char["RightHand"],
  75.         ["TargetOffset"] = CFrame.new(0,-Char["RightHand"].Size/2,0),
  76.         ["OffsetAngle"] = 0
  77.     },
  78.     ["LeftArm"] = {
  79.         ["ShoulderW"] = nil,
  80.         ["ElbowW"] = nil,
  81.         ["ULength"] = 0.95,
  82.         ["LLength"] = 0.95,
  83.         ["Offset"] = CFrame.new(-1.05,0.8,0),
  84.         ["Target"] = Char["LeftHand"],
  85.         ["TargetOffset"] = CFrame.new(0,-Char["LeftHand"].Size/2,0),
  86.         ["OffsetAngle"] = 0
  87.     },
  88.     --[[["RightLeg"] = {
  89.         ["ShoulderW"] = nil,
  90.         ["ElbowW"] = nil,
  91.         ["ULength"] = 1,
  92.         ["LLength"] = 1,
  93.         ["Offset"] = CFrame.new(0.5,-1,0),
  94.         ["Target"] = Char["RightFoot"],
  95.         ["TargetOffset"] = CFrame.new(0.1,Char["RightFoot"].Size/2,0),
  96.         ["OffsetAngle"] = 175
  97.     },
  98.     ["LeftLeg"] = {
  99.         ["ShoulderW"] = nil,
  100.         ["ElbowW"] = nil,
  101.         ["ULength"] = 1,
  102.         ["LLength"] = 1,
  103.         ["Offset"] = CFrame.new(-0.5,-1,0),
  104.         ["Target"] = Char["LeftFoot"],
  105.         ["TargetOffset"] = CFrame.new(-0.1,-Char["LeftFoot"].Size/2,0),
  106.         ["OffsetAngle"] = -175
  107.     },]]
  108. }
  109.  
  110. local InteractableAnimations = {
  111.     ["Locker"] = function(locker)
  112.         local Door = locker:FindFirstChild'Door'
  113.         local Handle = Door:FindFirstChild'Handle'
  114.         local rightArm = IKLimbs["RightArm"]
  115.         local originalTarget = rightArm.Target
  116.         local originalTargetOffset = rightArm.TargetOffset
  117.         local Motor = Door:FindFirstChild'Motor'
  118.        
  119.         Motor.AngularVelocity = -10
  120.        
  121.         Root.Anchored = true
  122.         rightArm.TargetOffset = CFrame.new(0,0,0)
  123.         rightArm.Target = Handle
  124.         Door.CanCollide = false
  125.         wait(1)
  126.         Door.CanCollide = true
  127.         rightArm.Target = originalTarget
  128.         rightArm.TargetOffset = originalTargetOffset
  129.         Root.Anchored = false
  130.         Motor.AngularVelocity = 0
  131.         return
  132.     end
  133. }
  134.  
  135. local function solveIK(originCF, targetPos, l1, l2)
  136.     local localized = originCF:pointToObjectSpace(targetPos)
  137.  
  138.     local localizedUnit = localized.unit
  139.  
  140.     local l3 = localized.magnitude
  141.  
  142.     local axis = forwardV3:Cross(localizedUnit)
  143.  
  144.     local angle = acos(-localizedUnit.Z)
  145.  
  146.     local planeCF = originCF * fromAxisAngle(axis, angle)
  147.  
  148.     if l3 < max(l2, l1) - min(l2, l1) then
  149.         return planeCF * cfNew(0, 0,  max(l2, l1) - min(l2, l1) - l3), -pi/2, pi
  150.  
  151.     elseif l3 > l1 + l2 then
  152.         return planeCF * cfNew(0, 0, l1 + l2 - l3), pi/2, 0
  153.  
  154.     else
  155.         local a1 = -acos((-(l2 * l2) + (l1 * l1) + (l3 * l3)) / (2 * l1 * l3))
  156.         local a2 = acos(((l2  * l2) - (l1 * l1) + (l3 * l3)) / (2 * l2 * l3))
  157.  
  158.         return planeCF, a1 + pi/2, a2 - a1
  159.     end
  160. end
  161.  
  162. do
  163.     for key, value in next, IKLimbs do
  164.         local ULength = value.ULength
  165.         local LLength = value.LLength
  166.         local Offset = value.Offset
  167.         local UpperC0 = value.UpperC0
  168.         local LowerC0 = value.LowerC0
  169.         local Torso = Char.UpperTorso
  170.         local bColors = Char:WaitForChild("Body Colors")
  171.  
  172.         local UArm = Instance.new("Part",Char)
  173.         UArm.Color = bColors.TorsoColor3
  174.         UArm.TopSurface = "Smooth"
  175.         UArm.BottomSurface = "Smooth"
  176.         UArm.Size = Vector3.new(0.68,ULength,0.68)
  177.         UArm.CanCollide = false
  178.         local ShoulderW = Instance.new("Weld", UArm)
  179.         ShoulderW.Part0 = Torso
  180.         ShoulderW.Part1 = UArm
  181.         value.ShoulderW = ShoulderW
  182.         local SMesh = Instance.new("SpecialMesh", UArm)
  183.         SMesh.MeshId = "rbxasset://fonts/leftarm.mesh"
  184.         SMesh.Scale = Vector3.new(0.68,0.5,0.68)
  185.        
  186.         local UArmShirt = script.Arm:Clone()
  187.         UArmShirt.PrimaryPart.MainWeld.Part0 = UArm
  188.         UArmShirt.Parent = UArm
  189.        
  190.         local ElbowSkin = Instance.new("Part",Char)
  191.         ElbowSkin.Color = bColors.RightArmColor3
  192.         ElbowSkin.TopSurface = "Smooth"
  193.         ElbowSkin.BottomSurface = "Smooth"
  194.         ElbowSkin.Size = Vector3.new(0.68,0.68,0.68)
  195.         ElbowSkin.CanCollide = false
  196.         ElbowSkin.Shape = "Cylinder"
  197.         local ElbowSkinW = Instance.new("Weld", UArm)
  198.         ElbowSkinW.C0 = cfNew(0,-ULength/2,0)*cfAngles(0,0,math.rad(90))
  199.         ElbowSkinW.Part0 = UArm
  200.         ElbowSkinW.Part1 = ElbowSkin
  201.         local SMesh1 = Instance.new("SpecialMesh", ElbowSkin)
  202.         SMesh1.MeshId = "rbxassetid://2044091701"
  203.         SMesh1.Scale = Vector3.new(0.337,0.337,0.337)
  204.        
  205.         local LArm = Instance.new("Part",Char)
  206.         LArm.Color = bColors.RightArmColor3
  207.         LArm.TopSurface = "Smooth"
  208.         LArm.BottomSurface = "Smooth"
  209.         LArm.Size = Vector3.new(0.68,LLength,0.68)
  210.         LArm.CanCollide = false
  211.         local ElbowW = Instance.new("Weld", LArm)
  212.         ElbowW.Part0 = UArm
  213.         ElbowW.Part1 = LArm
  214.         value.ElbowW = ElbowW
  215.         local SMesh1 = Instance.new("SpecialMesh", LArm)
  216.         SMesh1.MeshId = "rbxasset://fonts/leftarm.mesh"
  217.         SMesh1.Scale = Vector3.new(0.68,0.5,0.68)
  218.        
  219.     end
  220. end
  221.  
  222. UIService.InputBegan:Connect(function(input, Occupied)
  223.     if not Active and not Occupied and input.KeyCode == Enum.KeyCode.F then
  224.         if CurrentlyInteractable then
  225.             Active = true
  226.             InteractableAnimations[CurrentlyInteractable.Name](CurrentlyInteractable)
  227.             Active = false
  228.         end
  229.     end
  230. end)
  231.  
  232.  
  233. while RS:wait() do
  234.     CurrentlyInteractable = nil
  235.     for i,v in pairs(workspace:FindFirstChild'InteractableObjects':GetChildren()) do
  236.         local Magnitude = (v.PrimaryPart.Position - Mouse.Hit.p).magnitude
  237.         local Magnitude2 = (v.PrimaryPart.Position - Root.Position).magnitude
  238.         if Magnitude < 1 and Magnitude2 < 3 then
  239.             InteractBtn.Enabled = true
  240.             InteractBtn.Parent = v.PrimaryPart
  241.             CurrentlyInteractable = v
  242.         end
  243.         if CurrentlyInteractable then
  244.         local CurCF = CurrentlyInteractable:GetPrimaryPartCFrame()
  245.             if Magnitude < (CurCF.p - Mouse.Hit.p).magnitude and Magnitude2 < (CurCF.p - Root.Position).magnitude then
  246.                 InteractBtn.Enabled = true
  247.                 InteractBtn.Parent = v.PrimaryPart
  248.                 CurrentlyInteractable = v
  249.             end
  250.         end
  251.     end
  252.     if not CurrentlyInteractable then
  253.         InteractBtn.Parent = script
  254.         InteractBtn.Enabled = false
  255.     end
  256.    
  257.  
  258.     for key, value in next, IKLimbs do
  259.         local OffsetAngle = value.OffsetAngle
  260.         local Torso = Char.UpperTorso
  261.         local TargetOffset = value.TargetOffset
  262.         local shoulderCF = Torso.CFrame * value.Offset * cfAngles(0,0,math.rad(OffsetAngle))
  263.         local TARGET_POS = value.Target.CFrame*TargetOffset.p
  264.         local ShoulderW = value.ShoulderW
  265.         local ULength = value.ULength
  266.         local LLength = value.LLength
  267.         local ElbowW = value.ElbowW
  268.        
  269.         local plane, shoulderAngle, elbowAngle = solveIK(shoulderCF, TARGET_POS, ULength, LLength)
  270.         ShoulderW.C0 = Torso.CFrame:toObjectSpace(plane) * cfAngles(shoulderAngle,0,0) * cfNew(0,-ULength/2,0)
  271.         ElbowW.C0 = cfNew(0,0,0) * cfNew(0,-ULength/2,0) * cfAngles(elbowAngle,0,0) * cfNew(0,-LLength/2,0)
  272.         --Root.CFrame = CFrame.new(Root.Position, Vector3.new(Mouse.Hit.p.X, Root.Position.Y, Mouse.Hit.p.Z))
  273.     end
  274.    
  275. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top