How to get the z axis value

I want to get the value of the z axis for ray tracing

I only have the X and Y value but i dont know how to get the z value without making the display into a box

I tried many equations to make it work correctly but the best i got is the fov being uneven
how it looks like using x y and my equation of z
image
how it looks like using only x y and the value of z is 0
image
on the z axis
image

for x = 0, screensize do
	for y = 0, screensize do
		--	task.wait()
	--	for z = 0,screensize do
		local z = (x + y) - y
		local part = Instance.new("Part")
		part.Size = Vector3.new(size,size,size)
		part.Position = Vector3.new(x * size,y * size + offsety,0)
		part.Anchored = true
		part.Parent = workspace.Grids
		--for z = 0, screensize do
		partmenu[part] = {part,x,y,z}
	--	task.wait()
			print(partmenu[part][4])
			--end
		--end
	end
end

a

4 Likes

wait are you trying to send a raycast or are you trying to get the axis needed for the raycast?

2 Likes

axis needed for the raycast, i send the raycast in the other portion of the script

who or what is sending the raycast?

1 Like

the same script in the portion i gave you its just getting the information for the ray cast they ray cast is being casted from the gray part not the parts just the one gray part

1 Like

okay so why not fire the raycast from the grey block, and put a part in your script which detects when it hits something and with that you can get RayResult and use RayResult.Instance.Position.X etc

use something like this

local rayOrigin = Vector3.new(0, 0, 0)
local rayDirection = Vector3.new(0, -100, 0)

local raycastResult = workspace:Raycast(rayOrigin, rayDirection)

change the direction to the part that is firing the cast and using the axis of that part which you want to use and also change origin to the part that is firing it

i didnt mean it like that the portion of the script i gave you is making a screen to display whats happening and the raycast will be based off the position of every part of the display
image
the square is whats displaying and the points is what its hitting i want it to be hitting like this
image
instead of this
image

can you tell me the system you are trying to make? if you do I might be able to help because Iā€™m having trouble understanding here

im trying to make a raytracing system but i cant find the value of z and i only have y and x values
in the loop i shown x and y values are based off the screen and they x and y values basically describe where the ray will go but i dont have a value for z that will work correctly