Make the player's head use the camera's rotation

How would I do this? I don’t want any clamps, any inverts, just the raw rotation of the camera. Like, have the head’s back always face the camera.

If you’re curious about my use case, I’m making a crosshair out of a surfacegui so it isn’t affected by the camera sway I have in place.

1 Like

I imagine you might be able to do something like

local camera = game.Workspace.CurrentCamera
local neck = character.Head.Neck
local baseNeckCFrameOffset = neck.C0:Inverse()
game:GetService("RunService").Heartbeat:Connect(function()
	neck.C0 = camera.CFrame * baseNeckCFrameOffset-- or baseNeckCFrameOffset * camera.CFrame if it's backwards
end)
1 Like

Sorry for the late response, I tried that, but it just flings my character into outer space.

Also, I’m using R6.

Have you tried setting the Head’s orientation to the orientation of CurrentCamera?

1 Like

Yeah, it does the same thing.

1 Like

Perhaps you could create a clone of the character’s head (along with their head accessories) and make their actual head (and head accessories) transparent, so it creates the illusion that this new head is the player’s real head. You’d have to constantly position it correctly (I don’t believe any constraints would work) and use the logic from the above replies (assuming they work I haven’t checked to see).

2 Likes

Disable the head’s collision so it doesn’t collide with the torso.

Roblox might automatically re-enable the head’s collision, so you’ll want to use a collision group.

-- on server
local physicsService = game:GetService("PhysicsService")
physicsService:CreateCollisionGroup("Head")
physicsService:CollisionGroupSetCollidable("Head", "Head", false)

-- on client in head rotation script
character.Head.CollisionGroup = "Head"
1 Like

Nope. Does the same thing.

Could you show me your code so I can try it out on my end and experiment?

Wait, the upper torso is probably still using the default collision group.

local physicsService = game:GetService("PhysicsService")
physicsService:CreateCollisionGroup("Character")
physicsService:CollisionGroupSetCollidable("Character", "Character", false)

-- on client in head rotation script
for _, part in ipairs(character:GetChildren()) do
	if part:IsA("BasePart") then
		part.CollisionGroup = "Character"
	end
end

Sure:

Client
local camera = workspace.CurrentCamera
local neck = script.Parent:WaitForChild('Torso'):WaitForChild('Neck')
local head = script.Parent:WaitForChild('Head')
local baseNeckCFrameOffset = neck.C0:Inverse()

game:GetService("RunService").RenderStepped:Connect(function()
	head.CollisionGroup = "Head"
	neck.C0 = camera.CFrame * baseNeckCFrameOffset
end)
Server
local physicsService = game:GetService("PhysicsService")
physicsService:CreateCollisionGroup("Head")
physicsService:CollisionGroupSetCollidable("Head", "Head", false)

Also, your edited code does the same thing unfortunately. :confused:

RobloxStudioBeta_ffKt0Nw8tq
I’m not being flung on my end, the head’s just in the wrong position. Let me experiment a bit more

Figured it out! I ended up just using a fake head like xendatro suggested, and setting the fake head’s CFrame to the camera’s. You could probably make this work with the joints too, but I won’t bother since this works for my use case.

local Camera = workspace.CurrentCamera
local RealHead = script.Parent:WaitForChild('Head')
local FakeHead = RealHead:Clone()
FakeHead.Name = 'FakeHead'
FakeHead.Transparency = 1
FakeHead.CanCollide = false
FakeHead.Anchored = true
FakeHead.Parent = script.Parent

game:GetService("RunService"):BindToRenderStep('FakeHeadMovement', 2000, function()
	FakeHead.CFrame = CFrame.new(RealHead.CFrame.Position) * Camera.CFrame.Rotation
end)

If anyone’s curious, this is how the camera sway looks now (A LOT BETTER.):

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.