#Neck C0 facing camera

1 messages · Page 1 of 1 (latest)

astral roost
#

Ive been trying to make it so that the neck's orientation follows the player camera's orientation so that it seems like when even the camera turns, you will know from how to player's head is turned. It works when the player does not move at all but then the player moves and spin, the movement orientation adds up with the camera orientation...

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local neck = character:WaitForChild("Head"):WaitForChild("Neck")
local camera = workspace.CurrentCamera

local function updateNeckC0()
    local NeckOriginalC0 = neck.C0.Position
    local targetPosition = camera.CFrame.Position
    neck.C0 = CFrame.new(NeckOriginalC0, targetPosition) * CFrame.Angles(0, math.rad(180), 0)
end

RunService:BindToRenderStep("UpdateNeckC0", Enum.RenderPriority.Camera.Value + 1, updateNeckC0)
smoky pebble
#

you could try to change it relative to a bodypart like the torso

#

so when you rotate your character it rotates with it

#
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local head = character:WaitForChild("Head")
local upperTorso = character:WaitForChild("UpperTorso")
local neck = head:WaitForChild("Neck")

local initialC0 = neck.C0

local camera = workspace.CurrentCamera

local function updateNeckC0()
    local CameraDirection = camera.CFrame.LookVector
    local TorsoCF = upperTorso.CFrame

    local LookVector = TorsoCF:VectorToObjectSpace(CameraDirection)

    local Yaw = math.atan2(-LookVector.X, -LookVector.Z)
    local Pitch = math.asin(LookVector.Y)

    --[[ If you want you can also cap them if you want to not be able to turn your head 360 degrees
    Yaw = math.clamp(Yaw, math.rad(-60), math.rad(60))
    Pitch = math.clamp(Pitch, math.rad(-30), math.rad(30))
    ]]

    neck.C0 = initialC0 * CFrame.Angles(Pitch, Yaw, 0)
end

RunService:BindToRenderStep("UpdateNeckC0", Enum.RenderPriority.Camera.Value + 1, updateNeckC0)