Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a position on a circle?

I need the parts to spawn around the object at a certain radius, how can I do this?

1 answer

✓ Accepted answer

It's possible with using sine and cosine, using them you can generate sine waves which is all you need for the circle, i am very good at geometry so i can't really explain how it's doing it, however, i can show you a code on how to do it:

local CIRCLE = math.pi * 2
local RADIUS = 20

local original_part = workspace.Part

local function generate_random_angle()
	return math.rad(math.random(0, 360))
end

local function create_part()
	local part = Instance.new("Part")
	part.Anchored = true
	part.Size = Vector3.new(1, 1, 1)
	
	return part
end

local function create_part_around_circle(original_position, angle, radius)
	local part = create_part()
	part.Position = original_position + Vector3.new(math.sin(angle) * radius, 0, math.cos(angle) * radius)
	part.Parent = workspace
end

create_part_around_circle(
	original_part.Position,
	generate_random_angle(),
	RADIUS
)

pi * 2 is 360 degrees but in radians. generate_random_angle generates random angle from 0 to 360 and converts it into radians using math.rad so it can work with sine and cosine, in create_part_around_circle function the position is the original part's position + offset, the offset is random sine and cosine number multiplied by the radius, the radius is defined in studs, sorry but this is all i can explain.

3 comments

1

assuming you know how sin and cos work in a triangle, consider this circle with a radius of 1. using the inner angle, any point always has a horizontal position of cos and and a vertical position of sin. since this is a 1 radius circle, just multiply by radius. https://www.mathsisfun.com/geometry/images/unit-circle-sin-cos-tan.svg

1

that's why sin and cos look like waves with a maximum of one, because they are showing the offset of some point on this circle.

0

oh shoot mate thanks, i knew why they were making the waves but after looking on the image i am now pro math B)

This discussion is preserved as it was. New answers, comments, and votes are closed.