Hello. I’m currently struggling with my character’s arms, when holding a tool, do not follow the player’s mouse like the rest of the upper body. My tool uses a Motor6D
joint where the handle is, as well as plays an animation when equipped if that is applicable to my issue. I’ve searched around and tried a few things with minimal results. Also wondering if it is possible to see the character’s upper body rotation/movement across all clients because it is only visible to the singular client.
Here is the code I currently have for the player’s upper body to follow the mouse, as well as a video:
-- Get services
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
-- Get player instances
local player = Players.LocalPlayer
local playerMouse = player:GetMouse()
local camera = workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local neck = head:WaitForChild("Neck")
local torso = character:WaitForChild("UpperTorso")
local waist = torso:WaitForChild("Waist")
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local neckOriginC0 = neck.C0
local waistOriginC0 = waist.C0
-- Get velocity
neck.MaxVelocity = 1/3
-- Function to aim player's body at mouse
RunService.RenderStepped:Connect(function()
local cameraCFrame = camera.CoordinateFrame
if character:FindFirstChild("UpperTorso") and character:FindFirstChild("Head") then
-- Get body part positions
local torsoLookVector = torso.CFrame.lookVector
local headPosition = head.CFrame.p
if neck and waist then
if camera.CameraSubject:IsDescendantOf(character) or camera.CameraSubject:IsDescendantOf(player) then
local point = playerMouse.Hit.p
local distance = (head.CFrame.p - point).magnitude
local difference = head.CFrame.Y - point.Y
neck.C0 = neck.C0:lerp(neckOriginC0 * CFrame.Angles(-(math.atan(difference / distance) * 0.5), (((headPosition - point).Unit):Cross(torsoLookVector)).Y * 1, 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)