Hi, I’m making a game and I added head looking to my game from okeanskiy’s tutorial, but I’m now trying to rotate the arm to where the head is facing - 90 degrees. I’m having issues with this, since I don’t know how to work this.
This is code for the headlook and right arm rotation
local players = game:GetService("Players")
local lp = players.LocalPlayer
local char = lp.Character or lp.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local run = game:GetService("RunService")
local cam = workspace.CurrentCamera
local torso = char:FindFirstChild("Torso")
local neck = torso:WaitForChild("Neck")
local rightarm = torso:WaitForChild("Right Shoulder")
local y = neck.C0.Y
local rep = game:GetService("ReplicatedStorage")
local lastTick = tick()
run.RenderStepped:Connect(function(deltaTime)
local camdirec = root.CFrame:ToObjectSpace(cam.CFrame).LookVector
if neck then
-- Rotate neck (works fine)
neck.C0 = CFrame.new(0,y,0) * CFrame.Angles(0,math.rad(180),0) * CFrame.Angles(0,-camdirec.X,0) * CFrame.Angles(-camdirec.Y,0,0)
neck.C0 = neck.C0 * CFrame.Angles(math.rad(-90),0,0)
if tick() - lastTick >= 0.9 then
lastTick = tick()
rep.Events.NeckCF:FireServer(neck.C0)
end
-- Problem starts here
-- Rotate arm (head looking straight forward should point the arm down)
-- When the head looks up (lets say straight up), the arm should point straight
local x, y, z = neck.C0:ToEulerAnglesXYZ()
rightarm.C0 = CFrame.new(rightarm.C0.Position) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), -x)
end
end)
This is how it looks when the code is ran:
w
This is how I want it to look: