I am trying to spawn parts with a magnitude of 50 from a part, the center. How do I go about doing this??
main = workspace.Enemy tower = workspace.Tower spawnradius = 50 while true do part = main:Clone() part.BrickColor = BrickColor.Random() mag = (part.Position - tower.Position).magnitude if mag <50 then -- I have no idea what to do. end end
I've thought about trying to understand how Roblox calculates magnitude but it has to do with something on absolute values. But being a 13-year-old, I have no idea how to find that. Any help would be appreciated. Solutions don't have to only rely on magnitudes.
You could use CFrames
to accomplish this since CFrame
is in object (local) space, so if you're referencing a point with the position (25,50,0)
you're actually referencing the point relative to the corresponding axes; 25 studs in the (object's) X axis, 50 studs in the (object's) Y axis and 0 studs in the (object's) Z axis.
math.randomseed(tick()) part.CFrame = CFrame.new(0,0,0) * CFrame.Angles(math.rad(math.random(0,360) - 180),math.rad(math.random(0,360) - 180),math.rad(math.random(0,360) - 180)) -- set random rotation part.CFrame = part.CFrame * CFrame.new(math.random(50,75),0,0) -- move 50-75 studs "forward" part.CFrame = CFrame.new(part.CFrame.Position) * CFrame.Angles(0,0,0) -- reset rotation