Mouse.Hit Inaccurate at longer ranges

So I’m trying to make a cannon that fires shells at the Mouse.Hit.p. But if the camera is too far away from what the mouse is pointing at, the Mouse.Hit.p just goes off in the distance about 10 000 studs. Which is strange considering it is supposed to only be 1000 studs long according to Robloxes API references.

The part is just there to show where the Mouse.Hit.Position is at.

What I have tried so far and clarification to somethings

  1. No, the Part is not colliding with the ray messing things up
  2. I have tried to just ditch the mouse.Hit completely by using my own raycasting, but that just kills performance if I go anywhere above 1000 studs as the maximum range (Which is necessary)
1 Like

I get the mouse hit position with mouseService. I don’t cast any rays. Instead i grab the mouse and then call the mouse.Hit property to get X, Y and Z.

1 Like

You don’t have anything welded to the players camera that you could be hitting do you? I’m going to try at longer distances but so far I cant reproduce it.

If it’s too far, simply increase the value you multiply the unit vector with. (i.e. change 1000 to 5000) The maximum length of a Ray on Roblox is 5000 studs.

EDIT: Also, make sure you ignore your own boat if you haven’t already based on the above replies. That is critical.

Yeah, just tested it again this time at further distance than I previously did and still cant reproduce. I would check the camera as previously stated. If the issue persist I would go over the code and make sure the projectile is going exactly where the mouse is pointed.

I had this exact same problem. I worked around it by using multiple continuous rays, since one single ray seemed to be inaccurate too.

Just to clarify. I’m NOT using ray cast. It’s the built in Mouse.Hit raycasting that is very inaccurate so I can’t just increase range. It’s not colliding with the ships or anything.

I think it’s just a feature to the Mouse.Hit function to help most situations. On wiki, it says the ray is 1000 long but what is actually happening is (My observations) The rays max length is 10 000 studds. This is the length where the object ends up if not colliding with anything. And the length the ray actually can collide is only 1000. So above 1000 studs the Mouse.Hit will automatically give you the position, 10 000 studds away.

I think Roblox is doing this because Roblox cant handle continues raycasting over 1000 studs so when ray extends 1000 studds, Roblox automatically sets it to 10 000 studds away in the same look vector. So Mouse.Hit still can be used at longer ranges for simpler things like lasers that don’t require so much precision.

But it’s just a theory… A GAME THEORY!

1 Like