@ee0w, But it would be easier if you just use the CFrame.UpVector
Propertie. @Paintertable, i hope that you use Remotes Events, else the others players dont will see that your Character bend his Torso. I tried to make a script:
[[LocalScript]]
local Player = game.Players.LocalPlayer
local UpperTorso = Player.Character:WaitForChild("UpperTorso")
local Head = Player.Character:WaitForChild("Head")
local RE = game.ReplicatedStorage.RemoteEvent
local CameraLookVector
local HeadLookVector
game:GetService("RunService").RenderStepped:Connect(function()
CameraLookVector = workspace.CurrentCamera.CFrame.LookVector
HeadLookVector = Head.CFrame.LookVector
RE:FireServer(math.acos(Vector3:Dot(CameraLookVector, HeadLookVector)))
end
[[ServerScript]]
local neckC0 = CFrame.new(0, 0.8, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
local waistC0 = CFrame.new(0, 0.2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, theta)
local neck = player.Character.Head.Neck;
local waist = player.Character.UpperTorso.Waist;
neck.C0 = neckC0 * CFrame.fromEulerAnglesYXZ(theta*0.5, 0, 0);
waist.C0 = waistC0 * CFrame.fromEulerAnglesYXZ(theta*0.5, 0, 0);
end)
Edit:
Here is the Updated script:
[[LocalScript]]
local InputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local UpperTorso = Player.Character:WaitForChild("UpperTorso")
local Head = Player.Character:WaitForChild("Head")
local RE = game.ReplicatedStorage.RemoteEvent
local CameraLookVector
local HeadLookVector
local Aiming
spawn(function()
InputService.InputBegan:Connect(function(key)
if key == Enum.UserInputType.MouseButton2 then --You can change the Key/InputType with another Key/InputType of you choise
Aiming = true
end
end)
InputService.InputEnded:Connect(function(key)
if key == Enum.UserInputType.MouseButton2 then --You can change the Key/InputType with another Key/InputType of you choise
Aiming = false
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
CameraLookVector = workspace.CurrentCamera.CFrame.LookVector
HeadLookVector = Head.CFrame.LookVector
RE:FireServer(math.acos(CameraLookVector:Dot(HeadLookVector)), Aiming)
end)
end)
[[ServerScript]]
local neckC0 = CFrame.new(0, 0.8, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
local waistC0 = CFrame.new(0, 0.2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, theta, aiming)
local neck = player.Character.Head.Neck;
local waist = player.Character.UpperTorso.Waist;
if aiming then
neck.C0 = neckC0 * CFrame.fromEulerAnglesYXZ(theta*0.5, 0, 0);
waist.C0 = waistC0 * CFrame.fromEulerAnglesYXZ(theta*0.5, 0, 0);
end
end)