My gun works, it will shoot at the object I click on. However, if I shoot where the distance is further that the “direction cap” or into the sky, no RaycastResult is created.
workspace:Raycast(Ray.Origin, Ray.Direction * direction_cap) --For this example, direction_cap will be 500
[A]:[B]:
In [A], you can see that the bullet’s are working when I shoot at an object.
In [B] however, when the camera is aimed at the skybox or just out of the reach of the “direction cap”, no bullets are made.
Is there a solution to this?
So far the only solution I can think of is to make an invisible boundary around the map and set the max distance direction_cap to the max. LEFT: No bullets because there is no boundary. RIGHT: Invisible boundary detected, hence, the bullets.
I don’t really want to do this though, I want to try and attempt to avoid exploiters from shooting anyone from anywhere.
Are there any better ways to do this?
In case you still don’t know what it is I am asking:
Question
How can I cast a ray into the sky, set a max distance, and return the RaycastResult?
This was way easier with workspace:FindPartOnRay but with the new one you can just assume, if nothing is hit, that result.Position would be Ray.Origin + Ray.Direction * direction_cap
So basically what youre saying
One specific way you might do this is like
local result = boringRaycastStuff or {Position = origin+direction*cap}
(You could also just port it over to the original raycast system but some people dont like using a functional and still useful system because roblox calls it deprecated, and of course they deprecate it for a reason but I dont think its the end all be all)
Dont forget to add the position to the second argument of the cframe.new along with the direction since it takes in an endpoint rather than a direction
Its probably working fine right now because youre lined up with the origin but itll start getting a bit funky as you move away from it
You’re right, I have that setup in the function it is being sent to.
I send the position with the event:
if (Result ~= nil) then
BH:FireServer(Camera.CFrame.Position, Result.Position, ViewModel, Muzzle.Position)
end
Result.Position = The position of CFrame.new(Ray.Origin, Ray.Direction * cap)
I’m going to most likely make another post asking how to send the bullet from the muzzle, but cast the ray from the camera. (As you can see, the bullets are being sent from the center of screen)