|
| 08 Jul 2011 07:45 PM |
| How would you get a random CFrame that's within the magnitude of a certain part? |
|
|
| Report Abuse |
|
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 08 Jul 2011 08:23 PM |
| Eh, what are you trying to make? That might help. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 08 Jul 2011 08:29 PM |
| How would I only get one vector3? |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2011 08:30 PM |
| I'm not sure what you mean by that. |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2011 08:32 PM |
I printed CF and got this :
Lots of vectors. I just need one simple CFrame. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|