Point arm towards mouse

Hello,

I’m trying to figure out how I can make the players’ right arm point towards the mouse, meaning I need to use Motor6D.Transform somehow. However, I’m awful with CFrames, and I’ve never worked with Motor6Ds before, so I’m a bit lost and could use some help.

This is what I have:

RunService.Stepped:Connect(function()
	RightShoulder.Transform = CFrame.new(RightUpperArm.Position, Mouse.Hit.p)
	RightShoulder.Transform = RightShoulder.Transform - RightShoulder.Transform.p
end)

Obviously, though, it doesn’t work. Hope someone can shed some light on how I’d be able to achieve this.

Note I’m looking into how to do this specifically with Transform, as - as far as I can tell - that is the best practice for this.

Thanks in advance.

Can’t say I’m really good with CFrame transformations when it comes to humanoids, but I took this head turning script and edited it slightly to suit your needs. It doesn’t use Transform, but it seems to work fine.

Credit here: Need help with torso and head following mouse - #6

Code:

--Credit to CleverSource
--Edited by Dr_K4rma

local RunService = game:GetService("RunService")

local Player = game.Players.LocalPlayer
local PlayerMouse = Player:GetMouse()

local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()

local Character = Player.Character or Player.CharacterAdded:Wait()
local RArm = Character:WaitForChild("RightUpperArm")
local RShoulder = RArm:WaitForChild("RightShoulder")

local Torso = Character:WaitForChild("UpperTorso")

local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local RShoulderOriginC0 = RShoulder.C0

RShoulder.MaxVelocity = 1/3

RunService.RenderStepped:Connect(function() 
		local CameraCFrame = Camera.CoordinateFrame
	
	if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then
		local TorsoLookVector = Torso.CFrame.lookVector
		local ArmPosition = RArm.CFrame.p
		
		if RShoulder then
			if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then
				local Point = Mouse.Hit.Position
				
				local Distance = (RArm.CFrame.p - Point).magnitude
				local Difference = RArm.CFrame.Y - Point.Y
				
				RShoulder.C0 = RShoulder.C0:lerp(RShoulderOriginC0 * CFrame.Angles(-(math.atan(Difference / Distance) * 1), (((ArmPosition - Point).Unit):Cross(TorsoLookVector)).Y * 1, 0) * CFrame.Angles(math.rad(90), 0, 0), 0.5 / 2)
				--Waist.C0 = Waist.C0:lerp(WaistOriginC0 * CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 0.5, 0), 0.5 / 2)
			end
		end
	end	
end)
3 Likes