generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Getting a random CFrame in a sphere magnitude?

Previous Thread :: Next Thread 
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
08 Jul 2011 07:45 PM
How would you get a random CFrame that's within the magnitude of a certain part?
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
08 Jul 2011 07:47 PM
I'm wondering that too.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Jul 2011 07:49 PM
"within the magnitude of a certain part"

magnitude is a property of a vector that shows the length of that vector.

I don't understand your question.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
08 Jul 2011 07:50 PM
This part is a sphere, correct?


function getRandomCFrame(ball)
local radius = ball.Size.x/2
local x, y, z = 0, 0, 0
print"Generating random coordinates..."
repeat wait()
x = math.random(-radius*100, radius*100)/100
y = math.random(-radius*100, radius*100)/100
z = math.random(-radius*100, radius*100)/100
until (x^2 + y^2 + z^2)^0.5 <= radius
return CFrame.new(Vector3.new(x, y, z), ball.Position)
end

local CF = getRandomCFrame(workspace.MySphere)



I'm not sure of an exact algorithm, so I used the loop. :s
Report Abuse
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
08 Jul 2011 08:18 PM
Like you have a part, 2x2x2, and pretend these a sphere surrounding it (5x5x5). How would I get a certain CFrame that's inside the Sphere but not outside of it? I've seen Crunch225's Testing Lab stuff, he has it in his desert game with the gun.
Report Abuse
stoopidfaic is not online. stoopidfaic
Joined: 02 Jul 2011
Total Posts: 284
08 Jul 2011 08:23 PM
Eh, what are you trying to make? That might help.
Report Abuse
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
08 Jul 2011 08:25 PM
Go to Crunch225's Ro-Bot Lab. And shoot the gun and look at where it landed. You'll see rays crossing out form where it is as sparks. I'm trying to acomplish that without spreading the spark so much it'll reach a infinite vector.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
08 Jul 2011 08:26 PM
function getRandomCFrame(radius, centerPart)
local radius = tonumber(radius) and radius or 2
local x, y, z = 0, 0, 0
print"Generating random coordinates..."
repeat wait()
x = math.random(-radius*100, radius*100)/100
y = math.random(-radius*100, radius*100)/100
z = math.random(-radius*100, radius*100)/100
until (x^2 + y^2 + z^2)^0.5 <= radius
return CFrame.new(Vector3.new(x, y, z), centerPart~=nil and centerPart.Position or Vector3.new(x, y, z))
end

local CF = getRandomCFrame(7, workspace.MyCenterPiece)
Report Abuse
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
08 Jul 2011 08:29 PM
How would I only get one vector3?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
08 Jul 2011 08:30 PM
I'm not sure what you mean by that.
Report Abuse
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
08 Jul 2011 08:32 PM
I printed CF and got this :

Lots of vectors. I just need one simple CFrame.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
08 Jul 2011 08:34 PM
CFrame has 12 values. The first 3 are position. I'm not sure what the other 9 are, but I think they all deal with rotation.
If you get 12 numbers, you've got a CFrame.
Report Abuse
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
08 Jul 2011 08:42 PM
Thanks dude.

But this just creates the spark one by one, how would I make it make them all at once?

function Fade(part)
for i = 1,100 do
wait()
part.Transparency = part.Transparency + 0.005
end
part:remove()
end

for i = 1,math.random(5,8) do

local CF = getRandomCFrame(5, game.Workspace.Part)

print(CF)

a = Instance.new("Part")
a.Name = "Spark"
a.CFrame = CF
a.Parent = game.Workspace
a.BrickColor = BrickColor.new("Bright yellow")
a.formFactor = 3
a.Transparency = 0.5
a.Size = Vector3.new(0.2,0.2,0.2)
a.Anchored = true
a.CanCollide = false

m = Instance.new("BlockMesh")

m.Parent = a

Fade(a)

end
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
08 Jul 2011 08:55 PM
function Fade(part)
for i = 1,100 do
part.Transparency = part.Transparency + 0.005
end
part:remove()
end


Take out the wait. XD :P
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
08 Jul 2011 08:56 PM
take out the wait in his function, also I know how to do his easily withot looping in 2D, however 3D is alil bit different but I'll sleep on it and can probably tell you tomorrow.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
09 Jul 2011 10:38 AM
function random(sphere)
local rand=math.random()*(sphere.Size.X/2)+1;
rand=rand*(-1^math.random());
return rand;
end

function getPoint(s)
return CFrame.new(s.CFrame.p+Vector3.new(random(s),random(s),random(s)).unit);
end


tell me how this works for ya.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
09 Jul 2011 03:14 PM
Wow...
You don't need all that fancy code to be honest... I totally forgot about unit vectors! X_X


function getPoint(centerPos, radius)
local x, y, z = math.random(-255, 255), math.random(-255, 255), math.random(-255, 255)
local v = Vector3.new(x, y, z)
return CFrame.new(centerPos+v.unit*radius, centerPos*v.unit*2*radius)
end

for i = 1, 100 do
wait()
local p = Instance.new("Part", workspace)
p.Anchored = true
p.Size = Vector3.new(1,1,1)
p.CFrame = getPoint( Vector3.new(0,0,0), 10 )
end



X_X
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image