Hello, I’m trying to make the arm point towards the mouse. Is there way to make it so it doesn’t go fully 360 degrees and have the actual angle of the arm also face the same direction.
So like if I move my mouse at a 45 degree angle the arm will also be 45 degrees.
It moves around in 360 degrees. Here’s the full script:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local lastMouseX, lastMouseY = 0, 0
local function updateArm()
local character = script.Parent
local rightArm = character:FindFirstChild("Right Arm")
local torso = character:FindFirstChild("Torso")
if rightArm then
local ArmMotor6D = torso:WaitForChild("Right Shoulder")
local jointPosition = ArmMotor6D.Part0.CFrame:toWorldSpace(CFrame.new(0.9,0.25,0.25))
local cframe = CFrame.new(jointPosition.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0.5, -1, -1)
local cframe = CFrame.new(jointPosition.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0.5, -1, -1)
local objectspace = ArmMotor6D.Part0.CFrame:ToObjectSpace(cframe)
local x,y,z = objectspace:ToOrientation()
x = math.clamp(x, math.rad(-45), math.rad(45))
y = math.clamp(y, math.rad(-45), math.rad(45))
z = math.clamp(z, math.rad(-45), math.rad(45))
local finalCFrame = CFrame.new(objectspace.Position) * CFrame.fromOrientation(x,y,z)
ArmMotor6D.C0 = ArmMotor6D.C0:Lerp(finalCFrame, 0.2)
end
end
mouse.Move:Connect(updateArm)
local player = game:GetService("Players").LocalPlayer
local TweenService = game:GetService("TweenService")
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local function updateArm()
local character = script.Parent
local rightArm = character:FindFirstChild("Right Arm")
local torso = character:FindFirstChild("Torso")
local motor : Motor6D = torso:WaitForChild("Right Shoulder")
local orgc1 = motor.C1
if rightArm then
local unitray = camera:ScreenPointToRay(mouse.X, mouse.Y, 1)
local objectspace = motor.Part0.CFrame:ToObjectSpace(CFrame.lookAt(motor.Part0.Position, motor.Part0.Position + unitray.Direction) * CFrame.Angles(math.rad(90),0,0))
local x,y,z = objectspace:ToOrientation()
x = math.clamp(x, math.rad(-360), math.rad(360))
y = math.clamp(y, math.rad(-360), math.rad(360))
z = math.clamp(z, math.rad(-360), math.rad(360))
local finalCFrame = CFrame.new(motor.C0.Position) * CFrame.fromOrientation(x,y,z) * orgc1.Rotation
local t = TweenService:Create(motor, TweenInfo.new(.45, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
C0 = finalCFrame
})
t:Play()
end
end
mouse.Move:Connect(updateArm)