I’m not good with CFrames, and i tried making something like arm aim towards the mouse with gun well after some tries it still didn’t turn out to work. So does anyone know how i actually could make this work?
my script:
local runservice = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character or plr.CharacterAdded:Wait()
local torso = char:WaitForChild("Torso")
local rshoulder = torso:WaitForChild("Right Shoulder")
local connection = runservice.Heartbeat:Connect(function()
local direction = mouse.Hit:ToOrientation()
local direction = Vector3.new(
mouse.Hit.LookVector.Y,
mouse.Hit.LookVector.X,
mouse.Hit.LookVector.Z)
rshoulder.C1 = CFrame.lookAt(rshoulder.C1.Position, rshoulder.C1.Position + direction)
end)
local rightArm = char:WaitForChild("Right Arm")
local function worldCFrameToC0ObjectSpace(motor6DJoint, worldCFrame)
local part1CF = motor6DJoint.Part1.CFrame
local c1Store = motor6DJoint.C1
local c0Store = motor6DJoint.C0
local relativeToPart1 =c0Store*c1Store:Inverse()*part1CF:Inverse()*worldCFrame*c1Store
relativeToPart1 -= relativeToPart1.Position
local goalC0CFrame = relativeToPart1+c0Store.Position--New orientation but keep old C0 joint position
return goalC0CFrame
end
local connection = runservice.Heartbeat:Connect(function()
local goalCF = CFrame.lookAt(rightArm.CFrame.Position, mouse.Hit.Position)
rshoulder.C0 = worldCFrameToC0ObjectSpace(rshoulder, goalCF) * CFrame.Angles(0,0, math.deg(-90))
end)