Search Unity

Random Spawning Obstacles

Discussion in 'Scripting' started by Fireking883, Jul 1, 2015.

  1. Fireking883

    Fireking883

    Joined:
    Nov 28, 2014
    Posts:
    50
    I am working on a game in which the player must doge random obstacles in a given area. The player moves forward at a speed and obstacles are spawned in front of them, but I have no idea on how to randomly spawn obstacles on the track. The idea is that the player constantly moves forward and can only move up and down, but it is in 3d, as the camera can rotate around the player. The track is just going to be a cube textured as the floor, but I want the obstacles as said above. I know this is vague, and I understand if you cannot help, but any help is appreciated!
     
  2. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    Can't you just have a bunch of set spawn positions in a list, and pick a random one every time you wish to spawn a new obstacle?
     
  3. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    If you are having a floor, which goes into depth (z-axis), you can always math random out a position on the current z value and x value. I do not know, how far you are in your game development, but I made a game, where the player is running on a sphere, so the sphere only rotates/moves, while the player sticks to his position, he can only run left or right, but it is looking like he would run forward. But thats just another guess of doing this kind of game. anyway, you can spawn your obstacles by asking where the player is and randomize the position with kind of cap for z and x axis.

    To get you further, you should look into:
    http://docs.unity3d.com/ScriptReference/Random.Range.html