|
| 14 Jan 2017 04:37 PM |
function ModuleMapFunction() local Colors = {"Dark stone grey", "Smoky grey", "Medium stone grey", "Fossil", "Mid gray", "Ghost grey", "Quill grey", "Pearl", "Lily white", "Institutional white"}
for i = 1, 50 do local Ceres = game.ServerStorage.Assets.Asteroids:GetChildren() local Asteroid = Ceres[math.random(1,#Ceres)]:Clone() Asteroid.BrickColor = BrickColor.new(Colors[math.random(1, 10)]) Asteroid.Anchored = false Asteroid.CanCollide = true Asteroid.Size = Vector3.new(math.random(100, 300), math.random(100, 300), math.random(100, 300)) Asteroid.CFrame = CFrame.new(math.random(-2500, 2500), math.random(-2500, 2500), math.random(-2500, 2500)) * CFrame.Angles(math.rad(math.random(1, 360)), math.rad(math.random(1, 360)), math.rad(math.random(1, 360))) Asteroid.Parent = game.Workspace.GameFolder wait() end game.ServerStorage.ModuleBool.Value = true end return ModuleMapFunction
Maybe I just did things wrong, but the idea was that the asteroids would be randomly sized, placed, and angled. However it seems that more often than not, the same asteroid as another is cloned, resized the same, and then placed at the exact same coordinates as others.
It's weird, because I have 9 different asteroid meshes, but it seems to only be the ones that are the same mesh that end up getting resized the same and placed at the same spot. |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 14 Jan 2017 04:37 PM |
| math.randomseed(tick()) at the top of your script |
|
|
| Report Abuse |
|
|
|
| 14 Jan 2017 04:50 PM |
| It's pretty much perfectly random for me, but what has been stated, math.randomseed(tick()) is good, especially for projects where you want it less pseudo-random than it is. |
|
|
| Report Abuse |
|
|
|
| 14 Jan 2017 04:59 PM |
Math.random isn't truly random (the first randomly generated number will pretty much always be the same and others after it would be similar) because it generates the number from the same seed each time. So for truly random results, you would have to set the seed used for value generation to something that isn't consistent such as tick(), like in pkenty's example, via math.randomseed()
|
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 14 Jan 2017 05:01 PM |
| 'There is no truly random in programming', A lot of people say this, but I tend to like to use the time it took to load one frame to generate random values |
|
|
| Report Abuse |
|
|
|
| 14 Jan 2017 05:43 PM |
| I have math.randomseed(tick()) commented out on the top of the script, which I left out when I posted this thread, but even with the randomseed the problem still persists. |
|
|
| Report Abuse |
|
|
|
| 14 Jan 2017 05:45 PM |
| Try math.randomseed((tick() % 1) * 1e7) |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 01:18 PM |
| Everything about that throws red flags up in my head. That's gonna crash my computer isnt it |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 01:20 PM |
it's not going to crash your computer
attempt to call girlfriend (a nil value) | (͠≖ ͜ʖ͠≖)👌 | nothin' like a good argument ¯\_(ツ)_/¯ |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 01:24 PM |
i tried it but the results are the same. There are still asteroids being spawn in similar spots :/
The only solution I can think of is to increase the number of roids being spawned and hope that evens out the ones that are going flying off into the distance due to the cframing problem.
Btw I have anchored off and gravity at zero. Since I'm CFraming the spaceships during flight rather than using welds and velocity objects the gravity is a good way to simulate somewhat realistic collisions in space. |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 01:26 PM |
| Try increasing the range, and then dividing. It might help a tiny bit. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 15 Jan 2017 01:26 PM |
@OP google: Casualist math.randomseed* site:forum.roblox.com/Forum/
People have this problem like once a day; it's because in the short term tick() isn't a great seed. tick()%1*1e6 is a better seed because it discards the integer part of tick() (which changes slowly with respect to time) and uses the fractional part (which changes rapidly with respect to time). |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 01:29 PM |
To be perfectly honest I don't really mind all that much if it's not very random. I just want to solve this problem with the roids being spawned in the same spots.
What if I were to change the code? Perhaps a way of putting all the current roids into a table and using magnitude or whatever to "detect" if the chosen spawn location is too close to another roid? |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 15 Jan 2017 01:33 PM |
This should work fine:
math.randomseed(tick()%1*1e6) function ModuleMapFunction() local Colors = {"Dark stone grey", "Smoky grey", "Medium stone grey", "Fossil", "Mid gray", "Ghost grey", "Quill grey", "Pearl", "Lily white", "Institutional white"}
for i = 1, 50 do local Ceres = game.ServerStorage.Assets.Asteroids:GetChildren() local Asteroid = Ceres[math.random(1,#Ceres)]:Clone() Asteroid.BrickColor = BrickColor.new(Colors[math.random(1, 10)]) Asteroid.Anchored = false Asteroid.CanCollide = true Asteroid.Size = Vector3.new(math.random(100, 300), math.random(100, 300), math.random(100, 300)) Asteroid.CFrame = CFrame.new(math.random(-2500, 2500), math.random(-2500, 2500), math.random(-2500, 2500)) * CFrame.Angles(math.rad(math.random(1, 360)), math.rad(math.random(1, 360)), math.rad(math.random(1, 360))) Asteroid.Parent = game.Workspace.GameFolder wait() end game.ServerStorage.ModuleBool.Value = true end return ModuleMapFunction |
|
|
| Report Abuse |
|
|
MK_0
|
  |
| Joined: 28 Aug 2010 |
| Total Posts: 1651 |
|
|
| 15 Jan 2017 01:39 PM |
| ####################################################### |
|
|
| Report Abuse |
|
|
MK_0
|
  |
| Joined: 28 Aug 2010 |
| Total Posts: 1651 |
|
|
| 15 Jan 2017 01:40 PM |
I like to use Random (d(0)t) org's API
|
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 01:42 PM |
Same results. Well I certainly do appreciate you guys trying to help. I know it's not easy to solve a dumb guy's problems when he can't give you proper information.
I'm going to go and try solving this from a different angle by creating a table and checking the magnitudes between vectors before allowing the asteroid to spawn lol |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 02:55 PM |
Ok So I attempted to create a function that runs through a table of asteroids spawned and checks the magnitude of each one against the newly chosen position but it didn't seem to work.
In my head the code reads that the local function checks each asteroid currently spawned against the newly chosen position and if sets the local Bool to true if it's farther than 160 or false if not and then at the end where it checks to see if [o] is at the end of the for loop by using #Roids, the asteroid table, checks to see if the final Bool value is either true or false. If true, sets the asteroid's CFrame to the chosen position, else it fires it's own function again to try again.
At least, that's what I see in the code. Since it did not work, I clearly did not write out the correct code. I am stumped. This problem is bugging me so much. If absolutely necessary I will write out specific coordinates for a preset map but I would really like to avoid that if at all possible D:
math.randomseed((tick() % 1) * 1e6)
function ModuleMapFunction() local Colors = {"Dark stone grey", "Smoky grey", "Medium stone grey", "Fossil", "Mid gray", "Ghost grey", "Quill grey", "Pearl", "Lily white", "Institutional white"}
local Roids = {} local CV = nil local CBool = false
local function RSC(AstroRoid) local Bool = false CV = CFrame.new(math.random(-2500, 2500), math.random(-2500, 2500), math.random(-2500, 2500)) for o = 1, #Roids do if (V##################V#####V.Z) - Roids[o].Position).magnitude > 160 then Bool = true else Bool = false end if o == #Roids then if Bool == false then RSC(AstroRoid) else AstroRoid.CFrame = CV * CFrame.Angles(math.rad(math.random(1, 360)), math.rad(math.random(1, 360)), math.rad(math.random(1, 360))) CBool = true end end end end
for i = 1, 20 do CBool = false local Ceres = game.ServerStorage.Assets.Asteroids:GetChildren() local Asteroid = Ceres[math.random(1,#Ceres)]:Clone() Asteroid.BrickColor = BrickColor.new(Colors[math.random(1, 10)]) Asteroid.Anchored = false Asteroid.CanCollide = true Asteroid.Size = Vector3.new(math.random(100, 300), math.random(100, 300), math.random(100, 300)) if i == 1 then Asteroid.CFrame = CFrame.new(math.random(-2500, 2500), math.random(-2500, 2500), math.random(-2500, 2500)) * CFrame.Angles(math.rad(math.random(1, 360)), math.rad(math.random(1, 360)), math.rad(math.random(1, 360))) Roids[i] = Asteroid else RSC(Asteroid) repeat wait() until CBool == true end Asteroid.Parent = game.Workspace.GameFolder wait() end game.ServerStorage.ModuleBool.Value = true end return ModuleMapFunction |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 02:59 PM |
| Let me rephrase that. It did technically work, but a couple of them still spawned too close and caused them to fly off, some hitting other asteroids on their way out of the map |
|
|
| Report Abuse |
|
|
ratrat07
|
  |
| Joined: 10 Oct 2010 |
| Total Posts: 11 |
|
|
| 15 Jan 2017 03:25 PM |
| There is no such thing as random, simply everything is taken from one seed, but with a good seed comes a more random feel even though it's just a computer using math to determine a set value. The reason nothing will ever be random on a computer is because computers can't think for them selves instead they're like a child being told to do their chores. So the only way to feel random is to set a seed based off tick() for my random needs I usually use math.randomseed(time()*tick()) it works pretty well in my opinion. |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 03:50 PM |
Well then it's clear that I need to simply pre-select coordinates myself and place the asteroids there. I didn't want to but if I can't fix this then I have no choice. At the very least it will solve this problem...
But there are still so many other things in other scripts that are going so wrong. I'm literally on the edge of tears here. I don't know why finishing this game is so important to me but it is. It's like a mountain I need to climb and I won't feel... idk fulfilled i guess if I don't. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 15 Jan 2017 04:03 PM |
@OP Create a prototype place that demo's this problem only and uncopylock it. Based on what you've provided and our reply, there is no reason for this not to behave in a random manner.
Also ignore rat, a fair amount of what they said is wrong//oversimplified. |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 04:10 PM |
I don't know how to demo it. When I test a local server I have the ability to pan the camera around and watch the asteroids malfunctioning as they're being placed. Then I can close the server and test it again.
The game itself has no way to "end" the current game yet and I wouldn't know where to start with that yet.
It seems like every baby step I take, a monster problem rears its ugly head.
I'm still having problems with the core server script's efficiency for the readied players waiting for the game to start and the people who replied to that either didn't read the script or just tried to tell me to use things I was already using. |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2017 04:11 PM |
| But if you promise me that I can trust you won't try to steal my game, I can add you on somewhere and give you the file, though I will have to set the meshes' mesh ids to nil so that they aren't invisible for you. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 15 Jan 2017 04:14 PM |
Just create a general environment that showcases this specific snippet how you normally use it//it being problematic.
Because all things equal, this sounds like an issue with setup rather than execution. |
|
|
| Report Abuse |
|
|