Hi!
I want to know, how i can random position inside part?
i have try to use math.random() but it outside part
can someone help mew about this?
Thanks! and sorry for bad english.
Hi!
I want to know, how i can random position inside part?
i have try to use math.random() but it outside part
can someone help mew about this?
Thanks! and sorry for bad english.
You need to study Vector3âs.
Hereâs an example:
local part = Instance.new("Part", workspace)
part.Position = Vector3.new(math.random(10), math.random(10),math.random(10))
Ummm i mean i wanna get random position inside part for part
Depends on what is the size of the part.
Oh simply use constraints for your random position:
Basically what you will want to do is set your âdefault pointâ at your parts Vector3 position then use the size of each of the partâs vertices in your math.random().
Uhh sorry i donât understandâŚ
https://i.gyazo.com/40043602a0b0aaf618194943edd8d317
local Part = game.Workspace.Part
local PartMoving = game.Workspace.PartMoving
PartMoving.CFrame = Part.CFrame * CFrame.new(math.random(-Part.Size.X/2, Part.Size.X/2),math.random(-Part.Size.Y/2, Part.Size.Y/2),math.random(-Part.Size.Z/2, Part.Size.Z/2))
This will position the part in the center of the outside part like so
this should work for what you need but it doesnât account for the size of the inside brick
NewPart.CFrame = OutSizePart.CFrame*CFrame.new(Vector3.new(math.random(-(OutSidePartSize.X/2), OutSidePartSize.X/2), math.random(-(OutSidePartSize.Y/2), OutSidePartSize.Y/2), math.random(-(OutSidePartSize.Z/2), OutSidePartSize.Z/2))
There are many people are answered, i donât know i will mark who as solution.
I believe it gets even more complicated if youâre working in negative quadrants so youâll need to include the absolute value of some variables.
if you go off the cframe of the first part it doesnât matter if itâs negative or not
Yeah I just saw your answer, it should be the proper solution!
But i wanna use MoveTo() i donât know how i can use your solution because iâm confused.
You are moving a humanoid to a random position ?
No iâm doing random meteor falling position i think iâm ok now but i donât know how to convert CFrame to Vector3
Simply:
local x = CFrame.new(1,2,3)
print("CFrame = "..x)
local y = x.p
print("Vector3 = "..y)
Error: > ServerScriptService.GameScript:280: invalid argument #1 to ânewâ (Vector3 expected, got CFrame)
Code on that line:
m:MoveTo( CFrame.new( Part.CFrame * CFrame.new(math.random(-Part.Size.X/2, Part.Size.X/2),math.random(-Part.Size.Y/2, Part.Size.Y/2),math.random(-Part.Size.X/2, Part.Size.X/2))).Position )
Doesnât include the MoveTo but it is what it is Make blocks fall in random positions within the area of a block