You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I’ve been making an aerial pathfinding system (A* algorithm), and I used raycasting for collision detection between nodes, which seems to be causing an issue
What is the issue? Include screenshots / videos if possible!
When detecting whether a neighbour is avaliable, meaning you can access it from the neighbouring node without running into a collisionbox, the ray just ignores the wall that should stop the pathfinding from leaving the box
The green parts are the origin of the raycast, red parts are the destination of the raycast, it should clearly run into a part but it doesn’t?
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried messing around with raycastparams, I tried using both raydirection and raydestination, and I tried out some things I found here but nothing worked out
Here’s the part of the code that’s causing the issue
--for visuals
local visual1 = Instance.new("Part", workspace)
visual1.Anchored = true
visual1.CanCollide = false
visual1.Size = Vector3.new(1, 1, 1)
visual1.Color = Color3.new(0.015, 1, 0)
visual1.Position = node.Position
local visual2 = Instance.new("Part", workspace)
visual2.Anchored = true
visual2.CanCollide = false
visual2.Size = Vector3.new(.5, .5, .5)
visual2.Color = Color3.new(1, 0.25, 0.1)
visual2.Position = node2.Position
--making it so that raycast ignores the visuals (yes the walls are cancollide true that is not the problem)
--node is the origin, node2 is the destination
local params = RaycastParams.new()
params.RespectCanCollide = true
wait(.1)
local result = workspace:Raycast(node.Position, node2.Position - node.Position, params)
print(result)
--it returns result as nil even though it shouldn't
Desktop 2023.10.30 - 14.12.52.03 , just added print(node2.Position - node.Position) to the code (for some reason the beginning of the recording is buggy but it should be good enough)
does anything print if you get in front of the raycast? its odd because it findes the parts your making but not the wall and you said the wall for sure is cancollide true so see if it sees you?
When using Raycast I always get confused… so I better get the ray look vector then I multiply it by the distance I desire, like this:
local node2_Position = Vector3.new(15, 24, 30)
local node1_Position = Vector3.new(80, 20, 10)
local Distance = 50 -- distance of ray
local lookVector = (node2_Position - node1_Position).unit
local rayOrigin = node2_Position
local rayDirection = lookVector * Distance
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
Okay, so I tried this and another issue started happening, but now with the algorithm instead. It keeps checking the same positions over and over again even though they are removed from the possible nodes, so I might just close this because I’m wayyy too confused at this point