Hello, me and @sasial are trying to make a node generation that train will follow, we’re using node generation system by prebuilt nodes, and using rays to connect nodes. Our problem occurs when we try to connect nodes in curves using rays. The ray will simply continue and hit parts that we don’t want to hit.
Is there any way to rotate it, so we can make the curve?
Also here is our code:
function doray(i)
if i:IsA("Part") then
print("i is a part")
end
print(i.Name)
local o = Vector3.new(i.Orientation.Y --[[/2--]],0,300)
print(o)
local ray = Ray.new(i.Position,o)
local hit, position = workspace:FindPartOnRayWithIgnoreList(ray,{i})
if hit then
print("Found somethin'")
print(hit.Name,position)
print(hit)
if hit.BrickColor == BrickColor.new("Maroon") then
print("Node found. (:")
i.BrickColor = BrickColor.new("Lime green")
hit.BrickColor = BrickColor.new("New Yeller")
doray(hit)
else
print("Node not found")
if not hit:FindFirstChild("SelectionBox") then
print('new sb')
local sb = Instance.new("SelectionBox",hit)
sb.LineThickness = 1
sb.Color3 = Color3.new(0,255,0)
sb.Adornee = hit
end
end
else
print("Hit nothin'")
end
end
doray(workspace.Tracks.Start.PrimaryPart)
I am not quite understanding the question. It sounds like you are asking if you can make a curved ray, which from my understanding is not possible. You can draw many short, angled rays though, which would essentially be a curved line.
Can you please explain in a bit more detail what is happening, what you want to happen, and what you have tried to make that happen? Thanks!
Yes sure, we don’t want to make one large ray that will be from the start of the curve till the end of the curve, we want to use small ones. We just have problems of rotating it, because we both are really new to raycasting. Thank you for your response!
Do you currently have nodes between each point a ray should start and end? Or will it need to calculate the starting/stopping points on it’s own while going around corners?
Making a ray “rotate” is as simple as changing the direction component when creating the ray. You cannot alter the ray’s direction once it is created (from my understanding).
What is ‘o’ and why would that change anything? Can you show me more of the script? That line doesn’t do anything on its own so I can’t help you without seeing what else it does.
I think you should have both nodes including in creating the ray.
local node1pos, node2pos = node1.Position, node2.Position -- starting node, finishing node (then update the finishing node to be the new starting node, and the next node to be the new finishing node)
local ray = Ray.new(node1.Position, (node2.Position-node1.Position)) -- subtract the first node's position so that it only travels the difference in points (rays dont go from point A to point B, they from point A to point B+A, so if you subtract pointA then you get pointB).
Yeah sorry, could you tell me the size of the node. It should be based off the long end, so If I knew which axis that was I could have something for ya.
The picture picture at the top is an error, because we weren’t able to change rotation of ray, the picture at the bottom is exactly what we want to do. Imagine nodes like dots that are in the middle line (the color is maroon), all nodes are placed here.