Orientate model to player's head?

Hello!

I am working on a project and I’m making a entity similar to “Screech” from Doors.

Basically, once every 1-10 seconds the player is locked in place and has a vision of an eye, now I have everything done except for the part of orientating the eye model towards the player’s head.

I have tried a lot of different stuff, CFrame.lookAt doesn’t work, and if I try and simply orientate it using angles it doesn’t always result the same, and I need it to always orientate to the player’s head no matter where they’re facing.

local player = game.Players.LocalPlayer
local visionAssets = game.Workspace.VisionAssets
local visionSounds = game.Workspace["Vision Sounds"]

while wait() do
		
	local randomTime = math.random(1,10)
	print(randomTime)
	wait(randomTime)
	
	player.CameraMode = Enum.CameraMode.LockFirstPerson
	player.Character:FindFirstChild("Humanoid").WalkSpeed = 0
	player.Character:FindFirstChild("Humanoid").JumpHeight = 0
	
	wait(2)
	local effect = visionAssets.VisionEffect:Clone()
	visionSounds.Warning:Play()
	effect.Parent = game.Lighting
		
	local watcher = game.Workspace.VisionAssets["Lucid Watcher"]:Clone()
	watcher.Parent = game.Workspace
	watcher:SetPrimaryPartCFrame(CFrame.new(player.Character.EyeLocation.Position))
	
	watcher.PrimaryPart.Anchored = true
	
	wait(visionSounds.Warning.TimeLength)
	fadeOut()
	effect:Destroy()
	watcher:Destroy()
	player.Character:FindFirstChild("Humanoid").WalkSpeed = 16
	player.Character:FindFirstChild("Humanoid").JumpHeight = 7.2
	player.CameraMode = Enum.CameraMode.Classic
end

The code above is in a LocalScript in StarterGui. Everything works fine except the orientation.

Can anyone help? Thanks for reading!

Im not sure but i think you can do something like

game.Players.PlayerAdded:Connect(function(plr)

local char = plr.Character or plr.CharacterAdded:Wait()

game.Workspace.Creature.Orientation = char.Head.Orientation - 180
end)

This is all taking place in a LocalScript, I don’t want other people to see this scene.

Wait, do you want other people to see the character staring at you or like its a hallucination

It seems like you just need to make a new CFrame with the EyePosition and the Player Head position.

local newLookAt = CFrame.new(player.Character.EyeLocation.Position, player.Character.Head.Position)

If you put newLookAt inside watcher:SetPrimaryPartCFrame it should work.
Also SetPrimaryPartCFrame is deprecated and is being replaced with PivotTo it will function the same.

Tried this just now:

local newLookAt = CFrame.new(player.Character.EyeLocation.Position, player.Character.Head.Position)
	
	watcher:PivotTo(CFrame.new(player.Character.EyeLocation.Position), newLookAt)

Results are the same.

Yes, this is a hallucination that others shouldn’t see

That’s because you didn’t replace the First CFrame value with newLookAt you added it as the second.
PivotTo should only have one value.

try Roblox Local Parts - How to make Local Parts on Roblox - YouTube

watcher:PivotTo(newLookAt)

This makes the eye still look the wrong way,

I wasn’t sure if you meant this

watcher:PivotTo(CFrame.new(newLookAt))

But that results in an error.

That isn’t the issue, this is already all local, I just need to have the eye face towards the player.

The first one works you just need to apply a new CFrame to it to angle it.

watcher:PivotTo(
	newLookAt * CFrame.Angles(
		math.rad(180),
		0,
		0
	)
)

That’s your solution.

It’s not going to work right off the bat unfortunately.

You’re going to have to adjust the math.rad value by both it’s 180 number(should only have to experiment with -90, 90 and -180, 180) and placement within’ the CFrame.Angles if you can’t figure this out yourself I can’t hold your hand on this.

Oh, my mistake. I’ll play around with the angles.

Thank you for the help, it worked.

I’m glad it works.
Goodluck on your project!

1 Like