How would I get the mouse's position without Mouse.Hit?

Hello!

So i’m making a gun. My issue is that if a player points their mouse into the sky, mouse.hit will do nothing.
Does anyone have a way to get a mouse’s position while the mouse is pointed up?

Thanks

1 Like

Are you sure you can’t just do Mouse.Hit.Position?

There is no hit when the mouse is looking up to the sky, from what I know.

I believe you might be referring to Mouse.Target, which would result as nil when you aim your mouse towards there

Another alternate would be to use GetMouseLocation, which returns back a Vector2 value of the X & Y positionings of the Mouse I suppose?

1 Like

I think using camera’s cframe plus the mouse as an offset would be more efficient?

Mouse.Hit should not be nil if you point it up in the sky. If I would take a guess as to what is happening, you are using ray like parts as bullets. Part’s size can’t go past 4000 so that may be your issue here if you are creating a part from the gun to the mouse.

To fix this, create a max distance the gun can shoot from and if it’s over that then set the bullet size to the max distance.

I believe that Mouse.UnitRay is always defined, which would mean that you can safely use Mouse.UnitRay.Direction.