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 » Scripters
Home Search
 

New part created in a random spot around a circle?

Previous Thread :: Next Thread 
Soybeen is not online. 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 is not online. 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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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 is not online. 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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
11 Jun 2016 03:57 PM
I already posted an example using math.max
Report Abuse
Soybeen is not online. 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 is not online. 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 is not online. BanTech
Joined: 31 Dec 2015
Total Posts: 886
11 Jun 2016 04:00 PM
could just do largest * 1.5
Report Abuse
Soybeen is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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