Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get z position from mouse.hit.p?

so, im trying to make a 2d shooter game with raycasting but the problem is, its 2d. so the ray will also use the z value to go into a direction where i dont want it to. so to do that im trying to make the ray disregard the z value.

2 comments

0

mouse.hit.p.z ?

0

scriptinghelpers is not a request site.

1 answer

✓ Accepted answer

Well your issue is, Mouse.Hit returns a CFrame. You can read up on those here, but essentially they store rotation data in addition to position data. This means that you can get the Z axis of a CFrame simply by doing CFrame.Z. So your final solution would be:

local mouse = Player:GetMouse()
local z = mouse.Hit.Z

If this answer was helpful, please don't forget to mark as solution, thx c;

1 comment

0

Mouse.Hit.P returns the Position Mouse.Hit returns the CFrame. https://developer.roblox.com/en-us/api-reference/property/Mouse/Hit

This discussion is preserved as it was. New answers, comments, and votes are closed.