atfdaj
(Quoniam)
March 31, 2024, 4:46pm
#1
I need to raycast in a array in the shape of a cone base on angle and height, light a spotlight:

I can’t use random lines in a cone since I’m using it for a light baking engine and I obviously can’t use shapecast for it.

Does anyone know of a method?

SavAlt17
(Xylo)
March 31, 2024, 4:53pm
#2
didnt you just ask for raycasting a sphere, now a cone??

ps - “don’t ask people for code”

I’m not quite sure what you’re asking, but does this work for you?

You’re saying “radius”, but I think you want a cone. Radius isn’t quite specific enough in this context.
i.e. if your LookVector is the black line in this image, you want to pick some velocity in the red cone:
[image]
I borrowed that image from this stackoverflow answer .
Here’s the top answer on that question translated into lua:
-- axis: center line of cone
-- angle: angle from center to edge of cone
-- returns: a random unit vector inside the cone, evenly distributed along the partial sur…
Edit: or possibly this, which spreads the lines out evenly?

Really good attempt, there’s just a few tweaks to some negatives and things you needed. I also cleaned up the if statement stuff but your method also would work.
local function EvenlyDistributeVectorsInCone(n, angle, axis)
if n == 0 then return {} end
if n == 1 then return { axis } end
local cosAngle = math.cos(angle)
local vecs = table.create(n)
local phi = math.pi * (3 - math.sqrt(5))
for i = 0, n - 1 do
local a = i / (n - 1)
local z = -1 + (1-cosAngle)*a
local radius = math.sqrt…
2 Likes

The fact that you answered this same question not twice but three times over the past 2 years is amazing.

2 Likes

atfdaj
(Quoniam)
March 31, 2024, 5:07pm
#5
I didn’t ask for code, I asked for a way? Not to mention the last one I had code but needed it to go in 3 dimensions.

tlr22
(FusionOak)
March 31, 2024, 5:14pm
#6
You really just need to pick points in a circle. Basically take a slice of the cone, and cast from the top of the cone through points in the circle you’ve sliced out of the cone. The specifics of how to pick those points on the 2D circle can change based on your goals. Specifically you need to pick an algorithm that distributes the points in the way you want or is at least usable.

1 Like