I am trying to cast a ray from the players head into the direction of the players head but the ray seems to shoot directly down instead
This code is so the player can grab things in front of them similar to cleaning simulator
local player = workspace:WaitForChild(script.Parent.Parent.Parent.Parent.Name)
local PlayerHead = player:WaitForChild("Head")
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace["CanClick"]}
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
raycastParams.IgnoreWater = true
script.Parent.InputBegan:Connect(function(_input)
local rayOrigin = PlayerHead.Position
local rayDirection = PlayerHead.Orientation
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if _input.UserInputType == Enum.UserInputType.MouseButton1 then
if raycastResult then
local testpart = game:GetService("ReplicatedStorage")["ClickedPart"]:Clone()
testpart.Parent = workspace
testpart.Position = raycastResult.Position
print(workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Name):FindFirstChild("Head").Orientation)
end
end
if _input.UserInputType == Enum.UserInputType.MouseButton2 then
if raycastResult then
local testpart = game:GetService("ReplicatedStorage")["ClickedPart"]:Clone()
testpart.Parent = workspace
testpart.Position = raycastResult.Position
print(workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Name):FindFirstChild("Head").Orientation)
end
end
end)
(the player is using a custom player modal and the code is located inside of a gui button that covers the whole screen)