Hello, sorry if that’s a dumb question, but:
I’m trying to make a pathtracing script. It scans from left to right, then rotates up by a bit.
I have this script that creates a direction for a ray.
However, when changing the x direction, it goes to a completely different direction, so it’s affected by itself?
I’m trying to create a direction that’s based on a 0, 0, 0 vector, so I can make it point where I want without it being affected by itself.
local fov = 60
— resolution
local resX = 10
local resY = 10
local xIndex = 0
local yIndex = 0
— function that creates the ray origin and direction
function getRay()
yIndex = yIndex + 1
— rotates up when xIndex gets past x resolution
if yIndex > resY then
yIndex = 0
xIndex = xIndex + 1
end
local baseDirection = Vector3.new(0, 0, 0)
— how much x and y rotates based on their index
local yIncrement = -fov / 2 + fov / resX * xIndex
local zIncrement = -fov / 2 + fov / resY * yIndex
local direction = baseDirection + Vector3.new(yIncrement, zIncrement, 0)
print(direction)
return Ray.new(eye.Position, direction)
end
The yellow parts in the first image get created each time I call the function, and have the same direction as the one in the function.
I expected the parts to rotate like the second image (that’s when I leave the direction’s x to 0):
scans from left to right.
Console, when I call the function multiple times:
-30, -24, 0
-30, -18, 0
-30, -12, 0
-30, -6, 0
-30, 0, 0
-30, 6, 0
…
-30, 30, 0
-24, -30, 0
-24, -24, 0
-24, -18, 0
-24, -12, 0
-24, -6, 0
-24, 0, 0
-24, 6, 0
-24, 12, 0
Sorry if it’s not very clear… Thanks!