Jump to content
  • Advertisement

Bobby Lawrence

Member
  • Content Count

    19
  • Joined

  • Last visited

Community Reputation

119 Neutral

About Bobby Lawrence

  • Rank
    Member

Personal Information

  • Interests
    |designer|programmer|
  1. Incredible! Its working perfectly. I have a splash screen where I create objects that are used throughout the game so I stuck a RNG initializing script onto that scene and I ask for a new number from RNG every time during the loop. It works like a charm! Thank you everyone for your help. This thread is done, please close it!
  2. I actually eliminated those functions from the problem already by testing without them. They seem to work well actually. They have their own baked in RNG. They rotate the objects, and also move the objects randomly just a bit to create a more organic nature feel to the levels. Here is the updated code in total:   void Start()     {         ResetTags();         SpawnUntilFull();         RNG();     }                       void SpawnUntilFull()     {                  Transform freePosition = NextFreePosition();         if (freePosition)         {             freePosition.tag = "Attempted";             MoveRandomly();             RandomAngleGen();             ChooseRandomly();                 if (n <= spawnChance)                 {                     LevelManager.breakableCount += 1;                     GameObject destructible = Instantiate(chosenGameObject, (freePosition.position + moved), Quaternion.Euler(0, 0, angle)) as GameObject;                     destructible.transform.parent = freePosition;                 }                          if (NextFreePosition())             {                 Invoke("SpawnUntilFull", spawnDelay);             }         }     }         void RNG()     {         float timeF = System.DateTime.UtcNow.Ticks;         int timeI = (int)timeF;         UnityEngine.Random.InitState(timeI);         n = UnityEngine.Random.Range(1, 101);     }         void ChooseRandomly()     {               if (n <= chance30hp) { chosenGameObject = asteroid30hp; }         else if (n <= chance20hp) { chosenGameObject = asteroid20hp; }         else if (n <= chance10hp) { chosenGameObject = asteroid10hp; }     }         void MoveRandomly()         {             float x = UnityEngine.Random.Range(-.4f, .4f);             float y = UnityEngine.Random.Range(-.4f, .4f);             moved = new Vector3(x, y, 0);         }         void RandomAngleGen()     {             angle = UnityEngine.Random.Range(0, 181);         }                 Transform NextFreePosition()         {             foreach (Transform childPositionGameObject in transform)             {                      if ((childPositionGameObject.childCount == 0) & (!childPositionGameObject.CompareTag("Attempted")))                 {                     return childPositionGameObject;                 }             }             return null;         }       void OnDrawGizmos()     {         Gizmos.DrawWireCube(transform.position, new Vector3(width, height));     }     void ResetTags()         {             foreach (Transform childPositionGameObject in transform)             {                 childPositionGameObject.tag = "Untagged";             }         }       }   I created the RNG() function and only called it once because after my initial research that was something people mentioned as potentially causing the problem. Should I build in a fresh call in every loop of the main function?
  3. Thank you Lactose! that is definitely helpful, and it was indeed an error. Thank you. Now when I set the spawnchance variable to 100, everything spawns as it should. However, the RNG problem from my last post does persist. 30 and below spawn 1 object, 31 and above spawn all. Same problem as before really. Some other error is being missed. Thanks for your help everyone. There are 30 spots in the level for objects. I just realized that, I doubt that is a coincidence.
  4. So I tried to seed with System.DateTime.UtcNow.Ticks and it does not work. I think I have stumbled onto the problem. I have my spawn chance set to 100. That can't be right. Since n cannot be greater than 100 given the random functions I am using, it should be filling every space in the level with objects. It is not, its only filling about half of them. What is going on? I have figured out that with my current code, if I put 30 or less in for the spawnChance only 1 object spawns. Same place, every time. If I put 31 or higher I get the same 15 spawns in the same places every time. This mystery is driving me nuts! What is wrong with my code? It is not the RNG I think. It's the code structure. Or perhaps both.
  5.   Well the tooltip for Time.realtimeSinceStartup says time in second since game start, should mean since the application was started, not the scene was loaded. Which is its current implementation to my knowledge. I read it very carefully actually. Thank you, I will try that.
  6. Well I tried seeding with the following code:    //Trying to seed with system time         float timeF = Time.realtimeSinceStartup;         int timeI = (int)timeF;         UnityEngine.Random.InitState(timeI);   and I am still running it during Start() and it has no effect on the results. It is as if the seed is always the same no matter whether I try to seed it or not. I start the game, and move between levels and every level has the same pattern every time.
  7.  I actually tried seeding it using that function, no luck yet with that. I'll try setting the seed as the time and see how that goes.
  8. This is my confusion. The docs seem to suggest that it seeds it to the system time but I am getting the same level layout at every level no matter when I load the levels. So it clearly is not doing that in the editor.Thank you, I will see if I can get it seeded with system time.(I'll be back if I can't figure it out)
  9. The script in question is attached to the parent of the positional game objects I use to spawn the relevant gameObjects. So it Start() is called at the beginning of each level.
  10. Greetings and Salutations!   I am hard at work on a mobile game project for IOS and have come to a crucial portion of development. The procedurally generated levels. My code is functional at the moment but it seems no matter what I try, I cannot get the Level layouts to vary from stage to stage. Ideally I would seed the RNG with the build index number(or another variable that varies stage to stage but is unique to each stage.) I want each stage's layout to appear random upon first encounter, and be the same each time the stage is entered. Below is the code I am using.  I am new to RNGs and am in my first year of programming, so definitely a novice. I have read up a bit about seeding, cryptographic RNG and various other techniques but everything I find online is outdated information that no longer works or at least I cannot get it to work in the current version of unity. Oh and as the title says I am using C#. Thank you for your help!       public GameObject asteroid10hp;     public GameObject asteroid20hp;     public GameObject asteroid30hp;       public int chance10hp;     public int chance20hp;     public int chance30hp;       private GameObject chosenGameObject;      void Start()     {         n = UnityEngine.Random.Range(1, 100);     } void SpawnUntilFull()     {                  Transform freePosition = NextFreePosition();         if (freePosition)         {                           MoveRandomly();             RandomAngleGen();             if (n <= chance30hp) { chosenGameObject = asteroid30hp; }             else if (n <= chance20hp) { chosenGameObject = asteroid20hp; }             else if (n <= chance10hp) { chosenGameObject = asteroid10hp; }                 if (n <= spawnChance)                 {                     LevelManager.breakableCount += 1;                     GameObject destructible = Instantiate(chosenGameObject, (freePosition.position + moved), Quaternion.Euler(0, 0, angle)) as GameObject;                     destructible.transform.parent = freePosition;                 }                          if (NextFreePosition())             {                 Invoke("SpawnUntilFull", spawnDelay);             }         }     }        Transform NextFreePosition()         {             foreach (Transform childPositionGameObject in transform)             {                      if ((childPositionGameObject.childCount == 0) & (!childPositionGameObject.CompareTag("Attempted")))                 {                     childPositionGameObject.tag = "Attempted";                     return childPositionGameObject;                 }             }             return null;         }  
  11. Bobby Lawrence

    Should I pursue game Development?

    I guess I didn't explain my problem very well. Sorry. I didn't even realize it was a thing until I noticed that my level structures seemed very non-random. I generate 30 different objects inside a script in the start function. They are a random object from 3 choices, which seems to work well or at least I don't notice a repeating pattern. It also gives them a semi random position offset from the position parent object, also seems to work fine.   The issue is that the pattern that appears on the screen when the level is loaded is the same every time the level is loaded. It was quite random the first time, but upon subsequent attempts at the same level, the objects are in the same pattern. Basically the function loops and asks if a position has an object or not, if it doesn't it tries to make one. Or rather, if it hasn't attempted to make one.   Relvlent code:   private int RNG()     {          return Random.Range(1, 100);     }   void SpawnUntilFull()     {           Transform freePosition = NextFreePosition();         if (freePosition)         {             MoveRandomly();                         RandomAngleGen();             if (RNG() <= chance30hp)             {                 chosenGameObject = asteroid30hp;             }             else if (RNG() <= chance20hp)             {                 chosenGameObject = asteroid20hp;             }             else if (RNG() <= chance10hp)             {                 chosenGameObject = asteroid10hp;             }             if (RNG() <= spawnChance)             {                 GameObject destructible = Instantiate(chosenGameObject, (freePosition.position + moved), Quaternion.Euler(0, 0, angle)) as GameObject;                 destructible.transform.parent = freePosition;             }         }         if (NextFreePosition())         {             Invoke("SpawnUntilFull", spawnDelay);         }     }   Transform NextFreePosition()     {         foreach (Transform childPositionGameObject in transform)         {             if ((childPositionGameObject.childCount == 0) & (!childPositionGameObject.CompareTag("Attempted")))             {                 childPositionGameObject.tag = "Attempted";                 return childPositionGameObject;             }         }         return null;     }
  12. Bobby Lawrence

    Should I pursue game Development?

    Well I must say, thanks again GeneralJist. You are ever helpful. I will definitely check out that link. And as it happens, I do have a question for you folks.   I have started the process of creating a procedural level generating engine and ran into the problem where when you use the typical random method it creates the same sequence because its always the same base seed from your system clock. I have looked online for some ways to create my own custom random number generator and it seems like it may be best to use the cryptography based random number generator. I have read that the downside to that method is that its very slow, would that slow down or impede the performance of my game too much? It seems like it may be overkill but the more simple fixes I have come across have not seemed to work. Most of the info is very outdated and does not work with the current Unity version. I am using c#. Thanks guys!
  13. Bobby Lawrence

    Should I pursue game Development?

    I have a full-time job. And I am not intending to work any less or change jobs unless I can find something better. Game development is a long term dream, not a short term job change.
  14. Bobby Lawrence

    Should I pursue game Development?

    My PM to GeneralJist: I actually really appreciated your post. Being so honest and forthright is definitely what I was and am looking for. I am going ahead for now developing my game. I am having a good time as of now, so I don't see much reason not to keep at it. Who knows how far I will take it, but I certainly feel more comfortable with c# every day and have been loving all the logic puzzles. I have definitely realized how much I enjoy the development side of game design. The struggle I have experienced is just with getting a handle of the language and syntax of c# itself. Everyday I get a bit more comfortable with different parts of c# and thus have more and more fun, and spend less time debugging.   How long was the Course? 45 hours of video instruction. I spent well over 100 hours completing the 2D portion of the course twice. I really don't know how many hours I actually spent because I did it in my free time over the course of about 6 months. I took a few breaks in the course due to a hospitalization and other life issues. It was a blast to create the projects and they really challenged me.   Update on my project. I have been spending 4-6 hours a day working on it the last few weeks and it is really coming along. I just yesterday built my first rudimentary procedural generation engine. It loads the destructible objects into the scene and every time there is a random number of them I can control based on a variable chance, their rotation and position are also randomized to give the levels an organic looks. I am emboldened by my progress lately and will definitely continue full steam ahead. I have a pretty good grasp of bug fixing now and am never stuck on one bug for more than a half hour or so. Every day I implement a new feature or two and am getting excited to be able to have my friends and family sit down to my first reasonable alpha to start getting feedback. That includes the artist and musicians I intend to collaborate with. I will update this post as I make meaningful steps towards finishing the project. Thank you all very much for your help.   Sorry about the sporadic nature of my posts, I definitely was not feeling defensive or hurt by anyone's post. You have all been realistic and honest. I absolutely appreciate that.
  15. Bobby Lawrence

    Should I pursue game Development?

    So I realized that I left out something extremely relevant in my OP. The biggest thing that launched me into game development was actually an online course. It is a great crowdfunded course with dozens of hours of video tutorials. It is a complete Unity Development class and I completed five separate game projects during that course. It was incredibly cheap at the time and seemed like a no brainier just to get my feet wet. Having said that I would still say even though I've spent a few hundred hours learning to code and creating half a dozen games, I am definitely still a huge newb. The games I made in order were: a simple number guessing game, a text adventure, a brick breaker, a top down shooter, and a plants vs zombies clone.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!