So I’m trying to make my weapons more reliable. Unfortunately, mouse.hit.p is totally unreliable in the first place. It seems to return points floating in the air. How can I avoid that?
If your mouse is over nothing (or the object is really far away), mouse.Hit will just return the endpoint of the ray it used to check if the mouse is over anything. Among other things, this is necessary if you want to make a laser gun that still shoots at the direction of your mouse, but doesn’t hit anything. If you want to distinguish between when the mouse is hitting air and when it hits a part, you can check for mouse.Target == nil (air).
I guess I can do that but it doesn’t like to go very far… If I use a custom ray, could I make it go any further?
If you use a custom ray, the furthest it can go is 1000 studs. If your object is further than that, you would need to raycast multiple times (if it hits the end, continue with another raycast from there).
Thanks for the info. So then the mouse only goes as far as 1,000 studs, I’m assuming?
That is likely, but you’d have to test to be sure.
Correct me if I’m wrong, but I thought the raycast functions were extended to have a maximum distance of 5,000 studs?
Max raycast length is nominally 5000 studs. Usually.
Making a custom raycast system instead is often a great idea, as you can use it to make the mouse drop though invisible and/or cancollide off objects.