I don't understand how you can convert a lookvector position to degrees relative to a players character

You can write your topic however you want, but you need to answer these questions:

1. What do you want to achieve? Keep it simple and clear!

   Understanding of how to convert a lookvector position to degrees.
  1. What is the issue? Include screenshots / videos if possible!

I saw a video where the persons shows how you can make your characters head follow your camera.

The final script is this:

local camera = workspace.CurrentCamera

local character = game.Players.LocalPlayer.Character
local root = character:WaitForChild("HumanoidRootPart")
local neck = character:FindFirstChild("Neck", true)
local yOffset = neck.C0.Y

local CFNew, CFAng, asin = CFrame.new, CFrame.Angles, math.asin

	local cameraDirection = root.CFrame:toObjectSpace(camera.CFrame).lookVector

	if neck then
		neck.C0 = CFNew(0 , yOffset, 0) * CFAng(0, -asin(cameraDirection.x), 0) * CFAng(asin(cameraDirection.y), 0, 0)

I don’t understand how they convert the lookvectors position to degrees.

To convert the position to degrees you have to do -asin(cameraDirection.x) and asin(cameraDirection.y) I get why you have to use asin since arcsine of opposite/hypotenuse=the angle of a right-angled triangle. Or opposite/1 (1 since magnitude of lookvector is one I think) or just the opposite, but how do you find out what the opposite site is and how does it work in 3d space when the unit circle is in 2d space?

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have searched around on trigonometry on the roblox devforum but I couldn’t find anything on lookvectors and how to convert it to degrees etc.

1 Like

What rig type are you using? R6 or R15?

This is from part two of the video

local tweenService = game:GetService("TweenService")

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer

local Character = Player.Character
local Root = Character:WaitForChild("HumanoidRootPart")
local Neck = Character:FindFirstChild("Neck", true)
local YOffset = Neck.C0.Y

local CFNew, CFAng = CFrame.new, CFrame.Angles
local asin = math.asin

	local CameraDirection = Root.CFrame:toObjectSpace(Camera.CFrame).lookVector
	if Neck then
		if Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
			Neck.C0 = CFNew(0, YOffset, 0) * CFAng(0, -asin(CameraDirection.x), 0) * CFAng(asin(CameraDirection.y), 0, 0)
		elseif Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
			Neck.C0 = CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0)

game.ReplicatedStorage.Look.OnClientEvent:Connect(function(otherPlayer, neckCFrame)
	local Neck = otherPlayer.Character:FindFirstChild("Neck", true)

	if Neck then
		tweenService:Create(Neck, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = neckCFrame}):Play()

while wait(1) do

Make a RemoteEvent in replicated storage.Then make a script in serverscript service

game.ReplicatedStorage.Look.OnServerEvent:Connect(function(player, neckCFrame)
	for key, value in pairs(game.Players:GetChildren()) do
		if value ~= player and (value.Character.Head.Position - player.Character.Head.Position).Magnitude < 10 then
			game.ReplicatedStorage.Look:FireClient(value, player, neckCFrame)