I am using a custom mouse position script that I made using popular methods, and I try to return a RaycastResult, but whenever I click the sky it returns nil as expected.
How can I make it return the position including the Exlude list I made but when I click the sky it will just return the position I clicked with the maximum distance.
local ClientModule = {}
ClientModule.MouseCast = function(Camera, Mouse, Params)
if Params == nil then
Params = RaycastParams.new()
end
local unitRay = Camera:ScreenPointToRay(Mouse.X, Mouse.Y)
local Raycast = workspace:Raycast(unitRay.Origin, unitRay.Direction * 500, Params)
if Raycast then
return Raycast
else
-- Return the position with the max 500 unit distance.
return unitRay.Origin + unitRay.Direction * 500 -- I can do this but this will not use the raycast params...
end
end
return ClientModule
There is no way I can use the Params in the other script that uses Raycast.Position, which returns nil if I click the sky… and that’s unfortunate.
I try to make it so if I click nothing it will still fire a ray with a limit of the provided range, this example is that I shoot a fireball projectile and when I press it again it fires onto the location of the fireball, I want it to ignore the fireball and cast the position that I click similar to Mouse.TargetFilter.
If it returns nil you have the direction you want to shoot, so then just vector normalize that. With the vector normalized you can then scale it to however you want but you have the direction and then you can just fire a fireball that way.