Mouse.hit is returning areas floating in the air?

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?

2 Likes

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).

6 Likes

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?

1 Like

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).

1 Like

Thanks for the info. So then the mouse only goes as far as 1,000 studs, I’m assuming?

1 Like

That is likely, but you’d have to test to be sure.

1 Like

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.

4 Likes

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.

2 Likes