Weird offset when trying to use ScreenPointToRay()

i was messing around in roblox studio but encountered an issue while making the player shoot a ray to damage the enemy: there was an offset that made long range shooting buggy and weird (it would offset the ray so you had to shoot the air in a specific spot to get it to hit instead of the actual part)

ive tried using the mouse positions and the viewportsize but both seem to return the same thing

not really sure if the problem is in the workspace:raycast() or the workspace.currentcamera:screenpointtoray()

1 Like

You’re supposed to use :ViewportPointToRay, :ScreenPointToRay offsets the Y coordinate by how tall the Roblox topbar is, while :ViewportPointToRay does not.

image
(from: Camera:ScreenPointToRay)

1 Like