I’m trying to raycast from the player’s torso in front to check if it hits anything. However, it ALWAYS prints no part!
I’m relatively new to raycasting so please bear with me.
This is a LocalScript in StarterPlayerScripts.
while task.wait(1) do
local params = RaycastParams.new()
params.IgnoreWater = true
local wall = workspace:Raycast(script.Parent.Parent.Character.Torso.Position, script.Parent.Parent.Character.Torso.CFrame.LookVector, params)
if wall ~= nil then
print("found wall!")
else
print("no part!")
end
end
How close are you to the part? It’ll only detect parts up to 1 stud away from the root’s centre. You probably need to make the ray longer by multiplying the direction by some number
local RAY_RANGE = 10 -- How many studs in front, editable
local params = RaycastParams.new() -- make params once
params.IgnoreWater = true
local character = script.Parent.Parent.Character -- define character as a variable
while true do
local cframe = character:GetPivot() -- gets character cframe
local result = workspace:Raycast(cframe.Position, cframe.LookVector * RAY_RANGE, params)
if result then
print("hit", result.Instance)
else
print("no part!")
end
task.wait(1)
end