I want to detect when the mouse is to the left of the player to the right of the player and above the player my attempt at this was;
local mouseRay = mouse.UnitRay;
local distance = (Vector3.new(mouse.X, mouse.Y, 0) - head.CFrame.p).Unit;
print(distance:Dot(head.CFrame.LookVector))
the problem here is the values go up when the mouse is on the left side and when the mouse goes to the top of the screen and I only wanna detect for the left and right value here is a video;
as you can see it increases when the mouse moves left or goes up and decreases when it goes right or down how can I separate these and not like one conjoined variable?
You can simply use Mouse position on screen and screen size (assuming that character is always at the center) to calculate whether the mouse is on the left or right
local PlayersService = game:GetService("Players")
local LocalPlayer = PlayersService.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
while task.wait() do
if Mouse.X > Mouse.ViewSizeX/2 then
print("Right")
else
print("Left")
end
end
local PlayersService = game:GetService("Players")
local LocalPlayer = PlayersService.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
Mouse.Move:Connect(function()
if Mouse.X > Mouse.ViewSizeX/2 then
print("Right")
elseif Mouse.X < Mouse.ViewSizeX/2 then
print("Left")
else
print("Center")
end
end)
Mouse:GetPropertyChangedSignal("Target"):Connect(function()
local Target = Mouse.Target
local Character = LocalPlayer.Character
for _, part in pairs(Character:GetChildren()) do
if part.Name == Target.Name then
--do code
end
end
end)
In that case you can use WorldToScreenPoint to get position of any bodypart on screen and then just compare the Mouse.X with the X of Vector3 returned by the function