Advertisement
scriptingtales

Roblox Player's Center of Mass locator Lua Sandbox

Mar 29th, 2024 (edited)
872
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 1 0
  1. Model0 = Instance.new("Model", script)
  2. script.Name = "CentOM"
  3. Part1 = Instance.new("Part")
  4. Part2 = Instance.new("Part")
  5. Part3 = Instance.new("Part")
  6. Model0.Name = "COM"
  7. Model0.PrimaryPart = Part1
  8. Part1.Name = "XPlane"
  9. Part1.Parent = Model0
  10. Part1.CFrame = CFrame.new(-0.140193939, 0, -13.3988838, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  11. Part1.Position = Vector3.new(-0.14019393920898438, 0, -13.398883819580078)
  12. Part1.Color = Color3.new(1, 0, 0)
  13. Part1.Size = Vector3.new(4, 0.5, 0.5)
  14. Part1.Anchored = true
  15. Part1.BottomSurface = Enum.SurfaceType.Smooth
  16. Part1.BrickColor = BrickColor.new("Really red")
  17. Part1.CanCollide = false
  18. Part1.Locked = true
  19. Part1.TopSurface = Enum.SurfaceType.Smooth
  20. Part1.brickColor = BrickColor.new("Really red")
  21. Part1.Shape = Enum.PartType.Cylinder
  22. Part2.Name = "YPlane"
  23. Part2.Parent = Model0
  24. Part2.CFrame = CFrame.new(-0.140193939, 0, -13.3988838, -4.37113883e-08, -1, 0, 1, -4.37113883e-08, 0, 0, 0, 1)
  25. Part2.Orientation = Vector3.new(0, 0, 90)
  26. Part2.Position = Vector3.new(-0.14019393920898438, 0, -13.398883819580078)
  27. Part2.Rotation = Vector3.new(0, 0, 90)
  28. Part2.Color = Color3.new(0, 1, 0)
  29. Part2.Size = Vector3.new(4, 0.5, 0.5)
  30. Part2.Anchored = true
  31. Part2.BottomSurface = Enum.SurfaceType.Smooth
  32. Part2.BrickColor = BrickColor.new("Lime green")
  33. Part2.CanCollide = false
  34. Part2.Locked = true
  35. Part2.TopSurface = Enum.SurfaceType.Smooth
  36. Part2.brickColor = BrickColor.new("Lime green")
  37. Part2.Shape = Enum.PartType.Cylinder
  38. Part3.Name = "ZPlane"
  39. Part3.Parent = Model0
  40. Part3.CFrame = CFrame.new(-0.140193939, 0, -13.3988838, -4.37113883e-08, 0, 1, 0, 1, 0, -1, 0, -4.37113883e-08)
  41. Part3.Orientation = Vector3.new(0, 90, 0)
  42. Part3.Position = Vector3.new(-0.14019393920898438, 0, -13.398883819580078)
  43. Part3.Rotation = Vector3.new(0, 90, 0)
  44. Part3.Color = Color3.new(0, 0, 1)
  45. Part3.Size = Vector3.new(4, 0.5, 0.5)
  46. Part3.Anchored = true
  47. Part3.BottomSurface = Enum.SurfaceType.Smooth
  48. Part3.BrickColor = BrickColor.new("Really blue")
  49. Part3.CanCollide = false
  50. Part3.Locked = true
  51. Part3.TopSurface = Enum.SurfaceType.Smooth
  52. Part3.brickColor = BrickColor.new("Really blue")
  53. Part3.Shape = Enum.PartType.Cylinder
  54.  
  55.  
  56. local remt = Instance.new("RemoteFunction", owner.PlayerGui)
  57.  
  58. remt.OnServerInvoke = function(p, COM)
  59.     Model0:PivotTo(COM)
  60. end
  61.  
  62.  
  63. NLS([[
  64. print(script.Parent.Name)
  65.  
  66. local COM = workspace.CurrentCamera:FindFirstChild("COM")
  67. if not COM then
  68.     COM = workspace.CentOM.COM
  69.     COM.Parent = workspace.CurrentCamera
  70. end
  71.  
  72.  
  73. local char = owner.Character
  74. local Humanoid = char.Humanoid
  75. local rootPart = char:WaitForChild("HumanoidRootPart")
  76.  
  77. local UIS = game:GetService("UserInputService")
  78.  
  79. local remt = script.Parent.RemoteFunction
  80. game:GetService("RunService").RenderStepped:Connect(function()
  81.     if UIS.MouseBehavior == Enum.MouseBehavior.LockCenter and not Humanoid.Sit then
  82.         local cx, cy, cz = workspace.CurrentCamera.CFrame:ToOrientation()
  83.         local rx, ry, rz = rootPart.CFrame:ToOrientation()
  84.         local rotRoot = CFrame.fromOrientation(rx, cy, rz) + rootPart.Position
  85.         local pos = rotRoot:PointToWorldSpace(rootPart.CFrame:PointToObjectSpace(rootPart.AssemblyCenterOfMass))
  86.         remt:InvokeServer(rotRoot.Rotation + pos)
  87.     else
  88.         remt:InvokeServer(rootPart.CFrame.Rotation + rootPart.AssemblyCenterOfMass)
  89.     end
  90. end)
  91.  
  92.  
  93. ]])
  94.  
  95.  
  96.  
  97.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement