RayCasting around the cylinders’ circumference?

Hey,
I’ve been wondering if there’s a simpler way to cast a ray(s) around the cylinder’s circumference, and if it’ll cause any latency issues if I do so? Thank you in advance

4 Likes

Latency would imply you are doing something over the network, and that’s not related to raycasting.

Could you explain your problem better? Take a step back and describe the concrete game development problem you are solving that has led you to asking this particular question. What are you trying to make?

4 Likes

I’m sorry, by Latency I meant to ask if the players will encounter any problems with FPS? That being said I’m still unsure if Rays have got to do anything with that, that’s why I’m asking. I don’t really have a problem, I’ve mentioned earlier that it is just a thought of what I’ve been wanting to do but never managed to because I lack knowledge.The image below shows what I want to do(View from the top obviously) Think of it as a sun which emits rays in a 2- Dimensional environment, then return the name of the part/object It touched.

It depends on how often you’re running these ray-casts. I think ray-casts aren’t really expensive to run, however, running that many every frame could cause some performance issues.

It would be more helpful if you provided more information such as how often you want to run this or what you’re trying to achieve with this (sometimes there are other better solutions).

1 Like

This is just for a simple Object detection around this cylinder. I’m thinking of it to run pretty often, say, every 0.1 seconds?

There’s probably not a perfect answer as far as lag goes, so you could always test it in the game you want to use it on, and try it with it off, try it with it on (at different speeds if there’s a lot of noticeable lag), etc.

1 Like

There’s another question regarding the overall code for the raycasting. How would I cast a ray around an object, from every direction specifically?

Great!

If you’re trying to raycast like the image suggests, you could always do something like:

local hitParts = {}

local numOfRays = 6
for i = 0,360,360/numOfRays do
    -- create a ray in direction of (ball.CFrame - ball.Position) * CFrame.Angles(0,0,math.rad(i))
    -- store values of hit and position in hitParts
end
1 Like

Something like this might help. I’ve split out the ray creation into a function just to clean up the loop a little bit. You’ll need to decide how many rays you want. I’ve put in 12, which means it’ll scan every 30 degrees and it’ll extend 100 studs from the middle of the cylinder.

You can hopefully do whatever you need with this:

function getRayAtAngle( part, degrees, distance )
    local ray = Ray.new( part.CFrame.p, ( part.CFrame * CFrame.Angles( 0, math.rad( degrees ), 0 ) ).lookVector * distance )
    return ray
end

local yourCylinder = game.Workspace.Cylinder -- Set to your cylinder
local numRays = 12
local searchDistance = 100 -- studs

-- Do the search
local frac = 360 / numRays
for angle = frac, 360, frac do
    local ray = getRayAtAngle( myCylinder, angle, searchDistance )
    local part = game.Workspace:FindPartOnRayWithIgnoreList( ray, { yourCylinder } )
    -- Do what you need to do with part
end
2 Likes

Exactly what I’ve been looking for, thanks a lot!

1 Like