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.
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.
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.