I am trying to have the top of the arm follow the target part (the target part always follows the mouse)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rightArm = character:WaitForChild(“Right Arm”)
local torso = character:WaitForChild(“Torso”)
local rightShoulder = torso:WaitForChild(“Right Shoulder”)
local targetPart = workspace:WaitForChild(“TargetPart”)
local function updateRightArm()
local targetPos = targetPart.Position
local targetX = targetPos.X
local torsoPos = torso.Position
local direction = Vector3.new(targetX - torsoPos.X, 0, 0).unit
local lookAt = CFrame.lookAt(torsoPos, torsoPos + direction)
local desiredC1 = torso.CFrame:ToObjectSpace(lookAt) * CFrame.new(1, 0.5, 0)
Mouse moves → Part follows Mouse → Arms follow Part
Doing this:
Mouse moves → Part follows Mouse
Mouse moves → Arms follow Mouse
Basically, make 2 functions/scripts/whatever separately and both Part and arms follow the mouse. Seems easier and should give the same result, I think?
Check this post I did some days ago. I was checking this problem for (something) following the mouse. In my case it was the whole character. It worked but not exactly how I wanted, hence the post. unfortunately I deleted the code and don’t have it, but some people commented a few solutions so you might want to check them out here
Hi CoolDude32w, I’d use basic trigonometry for this purpose, so something like this might work better;
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rightArm = character:WaitForChild("Right Arm")
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local Mouse = player:GetMouse()
local OriginalCFrameForRightShoulder = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0)
local function updateRightArm()
local RotationalPivot = rightArm.RightShoulderAttachment.WorldCFrame.Position - rightArm.CFrame.UpVector*0.5
local Angle = -math.asin((RotationalPivot.Y-Mouse.Hit.Y)/(RotationalPivot-Mouse.Hit.Position).magnitude)
rightShoulder.C0 = OriginalCFrameForRightShoulder*CFrame.Angles(0,0,Angle+math.rad(90))
end
game:GetService("RunService").RenderStepped:Connect(updateRightArm)
Let me know if you have any issues, or if you want an explanation to what I’ve done here.