Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Unity C# Challenge to randomise map

Discussion in 'ML-Agents' started by virajvaitha1995, Jun 5, 2022.

  1. virajvaitha1995


    Mar 22, 2020
    Hi all,

    I have a basic cube race game, where the cube is moving forwards and we have to dodge the obstacles using left or right keys as seen below:


    I wanted to randomize the obstacle placement using some random logic.
    I am a python developer and very new to C# so explaining it with some python code.

    I have 100 obstacle grouped under a obstacle parent. In my C# script under EpisodeBegin() I want to:
    - Create a list containing all gameobjects under the parent

    - for loop through the list as seen below
    y_start = 0 # First set the y axis location to 0

    for obstacle in obstacles:
    y_new = y_start + random_value # as long as it isn't 0 or 1 otherwise game could become to hard
    obstacle_position = obstacle.transform.position(x_random_position_between_min_max,0,y_new)
    y_start = y_new #this ensures obstacles keep getting placed further

    Any idea on how I can do this in C#?