Hey guys! Im currenlty working on a gun system and Im using C0 to look up and down. Now it does work, but it doesn’t look the best, can someone help me inprove this system to make it look more nice?
Example of it breaking.
https://i.gyazo.com/5506a11320828d413760e42755872f25.mp4
Code:
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local rightShoulder = char.Torso:FindFirstChild("Right Shoulder")
local leftShoulder = char.Torso:FindFirstChild("Left Shoulder")
local neck = char.Torso:FindFirstChild("Neck", true)
-- reset the c0s to these once u stop the renderstepped
local originalRightShoulderC0 = rightShoulder.C0
local originalLeftShoulderC0 = leftShoulder.C0
local originalNeckC0 = neck.C0
RunService.RenderStepped:Connect(function()
local angleComponent = -math.asin((mouse.Origin.Position - mouse.Hit.Position).Unit.Y)
rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(angleComponent, 1.55, 0)
leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(angleComponent, -1.60, 0)
neck.C0 = CFrame.new(0, 1, 0) * CFrame.Angles(angleComponent + 1.55, math.pi, 0)
end)
plr.CharacterAdded:Connect(function(newChar)
rightShoulder = newChar.Torso:FindFirstChild("Right Shoulder")
leftShoulder = newChar.Torso:FindFirstChild("Left Shoulder")
neck = newChar.Torso:FindFirstChild("Neck", true)
end)
script.Parent.Parent.Events.Arms.OnClientEvent:Connect(function()
print("RESETING")
rightShoulder.C0 = originalRightShoulderC0
leftShoulder.C0 = originalLeftShoulderC0
neck.C0 = originalNeckC0
script.Disabled = true
end)
EDIT
Please note that the part is welded to the head
Thank you