#Help with trigonometry
1 messages · Page 1 of 1 (latest)
i know that
This guide is pretty good at understanding it
Version française: https://devforum.roblox.com/t/comment-utiliser-cos-et-sin/1660043 This tutorial will explain you how to use cos and sin inside of a Roblox experience. In Roblox, you can access cos and sin with the math.cos() and math.sin() functions respectively. What are cos and sin Basically, cos and sin are mathematical functions, they ...
i know the basics of trigo..
for i = 1, 7 do
local formula = i * ((math.pi*2)/7)
local position = Vector3.new(math.cos(formula) * 5, 5, math.sin(formula) * 5)
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Position = position
part.Parent = workspace
end
^ creates a circle with parts
roughly the same idea
mhm. So in this case,
I'd prob need to do:
for i = 1,#Players:GetPlayers(), right?
yes
[that command would only run when more than 1 person is in server]
see where it says /7
in local formula
Mhm
That's the 'indicator' for how many bricks to create?
yes
so the 7 there in the for i =1,7 do has to be the same number as that /7?
very good.
If the above needs any clarification:
for i = 1,7 do
local formula = math.pi*2/7*i
local x = math.cos(formula) * 10 -- radius
local z = math.sin(formula) * 10 -- radius again
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Position = Vector3.new(x,5,z)
part.Parent = workspace
task.wait()
end
someone "simplified" it
its simply the same
true.
local Players = game:GetService("Players")
local exampleObject = game.Workspace.exampleObject
local function tpPlayers()
local TotalPlayers = #Players:GetPlayers()
for i = 1, TotalPlayers do
local formula = i * ((math.pi*2)/TotalPlayers)
local position = Vector3.new(math.cos(formula) * 5, 5, math.sin(formula) * 5)
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Position = position
part.Parent = workspace
end
end
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
local messages = Message:Split(" ")
if messages[1] == "!Circle" then
if messages[2]:lower() == "all" then
for _,player in pairs(Players:GetPlayers()) do
end
end
end
end)
end)
okay
i have this now
so what I need to do is
that *5 in the formula
is how spaced out it is
you could add that as a parameter to your admin system
local Players = game:GetService("Players")
local exampleObject = game.Workspace.exampleObject
local function tpPlayers(player)
local TotalPlayers = #Players:GetPlayers()
for i = 1, TotalPlayers do
local formula = i * ((math.pi*2)/TotalPlayers)
local position = Vector3.new(math.cos(formula) * 5, 5, math.sin(formula) * 5)
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Position = position
part.Parent = workspace
player.Character:PivotTo(part)
part:Destroy()
end
end
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
local messages = Message:Split(" ")
if messages[1] == "!Circle" then
if messages[2]:lower() == "all" then
for _,player in pairs(Players:GetPlayers()) do
tpPlayers(player)
end
end
end
end)
end)
should this work?
tho i dont really need the parts
is it possible to still spawn the players in a circle without the need of creating the parts
the pivotto thing seems a little off
all you need is two vector3s and your good
Player.Character.PrimaryPart.CFrame = CFrame.new( pos1, pos2 )
and it should point your character in the correct direction
make sure you only supply two vector3 values
local function tpPlayers(player)
local TotalPlayers = #Players:GetPlayers()
for i = 1, TotalPlayers do
local formula = i * ((math.pi*2)/TotalPlayers)
local position = Vector3.new(math.cos(formula) * 5, 5, math.sin(formula) * 5)
player.Character.PrimaryPart.Position = position
end
end
local function tpPlayers(player)
local TotalPlayers = #Players:GetPlayers()
for i = 1, TotalPlayers do
local formula = i * ((math.pi*2)/TotalPlayers)
local position = Vector3.new(math.cos(formula) * 5, 5, math.sin(formula) * 5)
local charpos = player.Character.PrimaryPart.Position
player.Character.PrimaryPart.CFrame = CFrame.new( charpos, position )
end
end
same thing right?
why does it matter
Do you want the players to face the spawner?
mhm
The above code will do that
simply just setting the position alone will not
thats what its doing
by providing two vector3 values
This is using the same method I just showed you
well
when i tested it
they didnt face to that part
local Players = game:GetService("Players")
local exampleObject = game.Workspace.exampleObject
local function tpPlayers(player)
local TotalPlayers = #Players:GetPlayers()
for i = 1, TotalPlayers do
local formula = i * ((math.pi*2)/TotalPlayers)
local position = Vector3.new(math.cos(formula) * 5, 5, math.sin(formula) * 5)
player.Character.PrimaryPart.CFrame = CFrame.new(exampleObject.Position,position)
end
end
so i changed
does that work?
not at all, ill now show a video.
Okay, here is the video:
It seems to work but has few issues.
local function tpPlayers(player)
local TotalPlayers = #Players:GetPlayers()
for INDEX,PLAYER in pairs(Players:GetPlayers()) do
local formula = INDEX * ((math.pi*2)/TotalPlayers)
local position = Vector3.new(math.cos(formula) * 5, 5, math.sin(formula) * 5)
PLAYER.Character.PrimaryPart.CFrame = CFrame.new(exampleObject.Position,position)
end
end
maybe this can help