Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get the player's head to look in the direction of the camera?

I've been trying to get this work for a while now, and can't get heads or tails of what I'm doing wrong. I'm trying to stick with using Motor6D's, as I have some modules using it, but I can't seem to get it to work.

So far I get the rotation by doing this:

local cf = Cam.CFrame:toObjectSpace(Cam.CFrame*CFrame.new(0,0,-1)) 
local ang = cf-cf.p -- rot

and then attempting to apply that to an existing CFrame,

ModelWelds["Neck"].C1 = CFrame.new(0, -.2, 0)*ang

but it doesn't work >:( Another option I have is just using an older outdated version, but I didn't make that, and would really like to be able to understand this one so i can apply it to other things. Any help?

1 comment

0

ModelWelds["Neck"].C0 = (Char.Torso.CFrame*CFrame.new(0,.2,0.2)):toObjectSpace(Cam.CFrame)*CFrame.Angles(math.rad(90),0,0) is the code line I'm currently using, and here is an example of it in action https://twitter.com/EdenojackRBLX/status/720639533105201152

1 answer

If there is a way to get the position of a camera (I don't know since I'm not a camera expert), you can set up the head's coordinate frame to look at the camera like this:

camera = game.Workspace.CurrentCamera -- Get the camera
player = game.Players.LocalPlayer -- Get the player
repeat wait() until player.Character
character = player.Character -- Get the character

while wait() do
	if character ~= nil then -- Check for character
		if character:FindFirstChild("Head") then -- Check for head
			character.Head.CFrame = CFrame.new(character.Head.Position,camera.Position) -- 'Position' isn't a valid member of the camera, but you get the idea. This sets the head's look vector to the camera's position.
		end
	end
end

1 comment

0

Its still not acting correctly I'm afraid :/ I've edited this heavily and its only made the head fly about at crazy positions and angles.

This discussion is preserved as it was. New answers, comments, and votes are closed.