New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

How to get a Z value using ScreenPointToRay?

Asked by 3 months ago
Edited 3 months ago

I am currently trying to get a Z value for an FPS (First Person Shooter) by making a gun create a ray positioned to the center of the players screen.

local players = game.Players.LocalPlayer
local mouse = player:GetMouse()
local cam = workspace.CurrentCamera
local camPos = cam:ScreenPointToRay(mouse.X, mouse.Y,  -- Z Value Here --)

I am very clueless on what to do here so please help.

1 answer

Log in to vote
0
Answered by 3 months ago
Edited 3 months ago

I never used ScreenPointToRay before but I assume its a 2D space coordinates, if you want to get a 3D space coordinates, try Mouse.Hit.Z Since it's a first person, mouse should be right on the center of the screen.

Ad

Answer this question