I want to be able to detect when the client looks up/down/straight.
So far I tried monitoring the player’s Head’s CFrame, the Head’s CFrame’s LookVector, the camera’s CFrame, and the camera’s CFrame’s LookVector by printing them and seeing which values changed as I moved the camera up and down. Couldn’t find anything that resulted with what I needed. Closest thing I got was monitoring the camera.CFrame.YVector, but it gives the same data if I look straight up, or straight down.
Looking straight up:
Looking straight down:
Question: How do I monitor when the player looks up or down? (First Person Game) Just need a generalized method.
I think I’ve seen something that does this, wait just a minute, I’ll go find it.
Edit: Okay, I’ve found it, try manipulating this code that detects when your’e looking certain places and creates a ray from the sun.
Code
wait(1)
— Made by Zued
local p = game.Players.LocalPlayer
local mouse = p:GetMouse()
local blur = Instance.new(‘BlurEffect’) blur.Parent = game.Lighting
while wait() do
local ray = Ray.new(p.Character.Head.Position, (p.Character.Head.Position - mouse.Hit.p))
local ignore = game.Players.LocalPlayer.Character
local hit, position, normal = workspace:FindPartOnRay(ray, ignore)
if (position - p.Character.Head.Position).Magnitude >= 30 then
blur.Size = 5
else
blur.Size = (position - p.Character.Head.Position).Magnitude/3
end
end
Hmm, I tried it but it has the same problem. Looking straight up and straight down yields the same value, since after it passes the midpoint the numbers start decreasing.
Looking straight up:
Looking straight down:
It does have a bit more functionality than what I was doing before, so thanks.
I just have to somehow differentiate when the player is looking up and down, since they give the same values.
If anyone has any other solutions, that would be great, otherwise I’ll just try working with this, or maybe disable looking up.
I’m not too sure about this, but you can use the dot product.
--quicc mafs
function UpOrDown(LookVector)
local LookVector = LookVector.Unit
local UpVector = Vector3.new(0, 1, 0)
--Should return a value within range [-1, 1]
return LookVector:Dot(UpVector)
end
If value is positive then you are looking up. If value is negative then you are looking down. See if this helps
Sorry for late response, but the code isn’t too helpful lol, its just me printing a bunch of different CFrames to see which one correlates with the value I want to track.
Going off of what space dice said, if you have a part directly in front of the player and they look up, you can use the Dot product to get what direction they are looking at.
local function UpOrDown(LookVector)
return LookVector.Y
end
(note that the dot product is more useful when you’re trying to determine how close a vector is to pointing in a specific direction – but when that direction is “up”, you can simplify things like this)