CeaselessSoul

ROBLOX - Point Arm Towards Mouse

Mar 21st, 2018
10,174
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. --- Services ---
  2. local Players = game:GetService("Players");
  3. local RunService = game:GetService("RunService");
  4. wait();
  5.  
  6. --- Declarations ---
  7. local Player = Players.LocalPlayer;
  8. local Character = Player.Character or Player.CharacterAdded:Wait();
  9.  
  10. local Mouse = Player:GetMouse();
  11.  
  12. --- Character ---
  13. local RightUpperArm = Character:WaitForChild("RightUpperArm");
  14. local RightShoulder = RightUpperArm:WaitForChild("RightShoulder");
  15. local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart");
  16.  
  17. --- Execution ---
  18. RunService.Stepped:Connect(function()
  19.     local hit = Mouse.Hit;
  20.    
  21.     -- add the lookVector * 5000 to the hit.p to make the point more "dramatic" (remove it and you'll see why I did this)
  22.     local direction = hit.p + (hit.lookVector * 5000);
  23.    
  24.     -- get the rotation offset (so the arm points correctly depending on your rotation)
  25.     local rootCFrame = HumanoidRootPart.CFrame;
  26.     local rotationOffset = (rootCFrame - rootCFrame.p):inverse();
  27.    
  28.     -- since CFrames are relative, put the rotationOffset first, and then multiple by the point CFrame, and then multiple by the CFrame.Angles so the arm points in the right direction
  29.     RightShoulder.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), direction) * CFrame.Angles(math.pi / 2, 0, 0);
  30. end)
Advertisement
Comments
Add Comment
Please, Sign In to add comment