Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to create ignore objects as a ray is casted?

Asked by 5 years ago

With my current skills, I can only create objects that rays ignore prior to the ray being created, but now I realise there's new objects being added to the game which parents are specific and a ray must ignore; however I am struggling to achieve this has a ray ignore lists must be defined prior to a ray being created. A mundane solution could be to create a second ray, however this would mean I will have to change a significant amount of code which could cause other problems and may affect performance. Another thing I would also like to know is if the following code:

for i = 10, 50 do
    --casting a ray function
end

Without any waits(), will this cause performance issues, I am attempting to create rays to see if the surrounding parts has anything between the ray origin and the part itself.

1 answer

Log in to vote
1
Answered by
mc3334 649 Moderation Voter
5 years ago

Hello Marmalados! Yes, there is a way to ignore parts and as a matter a fact multiple parts when your raycasting. Here is an example

Scripting

local IgnoreList = {} --insert part instances that you want to be ignored into this table

function MakeRay(StartPos, EndPos)
    local ray = Ray.new(StartPos, EndPos)
    local hit, V3pos = workspace:FindPartOnRayWithIgnoreList(ray, IgnoreList)
end

Scripting Context

What is shown above, is raycasting with ignored parts! We start by making an array of instances that will be ignored, then when the function is ran, we make our ray. From there, we can determine the rays final part with the list of instances we told it to ignore! With further questions/comments/concerns, please feel free to reply! ~mc3334

0
EDIT: to fix whats in your ignoretable, you could just use table.insert and table.remove to keep the list updated. And yes, raycasting with your I loop 5 times may cause a performance drop. Probs not too bad at all, but that's not a light math job... mc3334 649 — 5y
Ad

Answer this question