How can I get a random location within a radius of the object? Trying to spawn something at least 100-800 studs away. With a random radius around it of 1-360 degrees. I don’t like math.
Would look something like this, idk what to do with the rest.
local radius = math.random(1,360) -- random degree in radius
local magnitude = math.random(100, 800)
you could get a random position in a radius by:
first, creating a CFrame, which will be the offsetPosition (we’ll just name it offsetPosition) local offsetPosition =
which will include the random rotation local offsetPosition = CFrame.Angles(0, math.rad(radius), 0)
then you’ll offset that position in the -Z axis, which will move it outward from the center. local offsetPosition = CFrame.Angles(0, math.rad(radius), 0) * CFrame.new(0, 0, -magnitude)
and then you could just add the offsetPosition to the CFrame of the center of the radius.
local radius = math.random(1,360) -- random degree in radius
local magnitude = math.random(100, 800) -- distance it will be from nest
local offsetPosition = CFrame.Angles(0, math.rad(radius), 0) * CFrame.new(0, 150, -magnitude)
local rayOrigin = nest.Position + Vector3.new(offsetPosition)
print(rayOrigin)
local raycastResult = workspace:Raycast(rayOrigin, -200, raycastParams)