#raycast problem
1 messages · Page 1 of 1 (latest)
local function RaycastResulting()
local ScreenPosition = Crosshair.AbsolutePosition + Crosshair.AbsoluteSize / 2
local unitray = cam:ScreenPointToRay(ScreenPosition.X, ScreenPosition.Y)
local rayOrigin = unitray.Origin
local rayDirection = unitray.Direction * 1000 -- 1000 studs in front
local result = workspace:Raycast(rayOrigin, rayDirection)
return result
end
local RayResult = RaycastResulting()
local TargetPosition
if RayResult then
TargetPosition = RayResult.Position
else
local lookVector = plr.Character.Head.CFrame.LookVector
TargetPosition = plr.Character.Head.Position + lookVector * HoldRange
end
BodyPosition.Position = plr.Character.Head.Position + CFrame.new(plr.Character.Head.Position, TargetPosition).LookVector*HoldRange
** You are now Level 9! **
casting rays towards the sky returns nothing, you'd need to calculate the end position
im new to this raycasting thing, i really dont know nothing about it and im just learning more about it until i stumble upon this bug that i somehow cant even fix
raycasts only work when it hits a 3D object. If it doesnt hit or you're pointing a nothing it'll return nothing
you can get the end position with this formula Origin + (Direction * Distance)
okay ill see what i can do with it
and in this case, you'd need to lower your distance since you're making draggable objects
If ray doesn't hit just treat the position as being origin + whatever direction you put in as the 2nd argument