Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 11 Jun 2016 03:39 PM |
So, I posted this yesterday but received little helpful information.
I'm trying to create a new Part with reference to a pre-existing one named PartMain. The only issue is that I need this Part to spawn at a RANDOM position in a circle around PartMain, the circle's radius being PartMain's longest side (X or Z, Y discluded, this isn't a sphere) plus half the longest side of Part (again X or Z)
How could this be done?
|
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 11 Jun 2016 03:44 PM |
wouldn't just
local radius = 10 -- you should be able to find this yourself
part.CFrame = PartMain.CFrame*CFrame.Angles(0,math.rad(math.random(360)),0)*CFrame.new(0,0,-radius)
do it? or am I missing something about your question |
|
|
| Report Abuse |
|
|
|
| 11 Jun 2016 03:48 PM |
local origin = PartMain.Position local radius local angle = math.rad(math.random(359))
do local size = PartMain.Size local largest = math.max(size.X, size.Z) radius = largest + largest/2 end
-- create Part part.Position = origin + radius * Vector3.new(math.cos(angle), 0, math.sin(angle)) part.Parent = workspace
something like that should work |
|
|
| Report Abuse |
|
|
|
| 11 Jun 2016 03:50 PM |
| Oh you wanna change the second largest in "radius = largest + largest/2" so it's the largest side of part. wwoops |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 11 Jun 2016 03:55 PM |
How could I easily determine that without being like
local longestSide if size.X > size.Z then longestSide = size.X else longestSide = size.Z end
Any faster way to compare?
|
|
|
| Report Abuse |
|
|
|
| 11 Jun 2016 03:57 PM |
| I already posted an example using math.max |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 11 Jun 2016 03:57 PM |
t Or is that what math.max is doing for me already? (my real question is, what do you want me to change? XD)
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 11 Jun 2016 03:58 PM |
ah, yeah thought so, I've never seen math.max before so I wasn't sure which largest in the radius equation am I affecting?
|
|
|
| Report Abuse |
|
|
BanTech
|
  |
| Joined: 31 Dec 2015 |
| Total Posts: 886 |
|
|
| 11 Jun 2016 04:00 PM |
| could just do largest * 1.5 |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 11 Jun 2016 04:01 PM |
Sorry I'm confused, what would multiplying it by 1.5 do..?
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 11 Jun 2016 04:03 PM |
The new part's size will differ from the MainPart's size, so I mean it could work, but it might be either too much or too little buffer.
|
|
|
| Report Abuse |
|
|
BanTech
|
  |
| Joined: 31 Dec 2015 |
| Total Posts: 886 |
|
|
| 11 Jun 2016 04:07 PM |
radius = largest + largest/2 --could be radius = largest * 1.5
Just a bit neater and one fewer calculations to do |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 11 Jun 2016 04:08 PM |
Alright my head's spinning, I'll just take this code and run
Thanks all
|
|
|
| Report Abuse |
|
|