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 want to ray cast to a surface point of a model that I have. Basically, the model is an island which has a marker on top that is used for things such as the players nametag, I am also using this as the origin for my ray.
What is the issue? Include screenshots / videos if possible!
The issue is that the raycast hardly ever actually successfully detects a part even though how I am casting the ray should always contact a part.
At the moment my code determines a random part of the model and raycasts towards it, so at least the ray should collide with that part or any covering it.
The marker that is the origin, is 10 studs away from the island and every part of the island is within range considering the 25 distance.
function ReturnRandomSurfacePointOfIsland(island)
local raycastResults
local direction = (island.Island:GetChildren()[math.random(1, #island.Island:GetChildren())].Position - island.PrimaryPart.Position).Unit
print(direction)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {island.Island}
raycastResults = workspace:Raycast(island.PrimaryPart.Position, direction * 25, params)
print(raycastResults)
return raycastResults
end
Try excluding the origins part/model. Also, what is the output of the raycast result, is it nil or is there a hit? And to add on T3_MasterGamer’s suggestion, is CanCollide also turned on? Lastly check if there are any anything that affects the raycast result (e.g. parts in the way, changing the variable to something else, etc…)
If nothing else works try creating a part and raycasting to it just to make sure that the raycast is actually working