Randomise Scenes

Discussion in 'Buildbox 3.0' started by AaroArts, Sep 11, 2019 at 12:12 PM.

  1. AaroArts

    AaroArts Miniboss Boxer

    Joined:
    Jun 22, 2016
    Messages:
    1,507
    Likes Received:
    792
    Is it possible to randomise scenes based on distance like it is in BB2? So for example you can randomise 1-5 for 1000 pixels, then a bunch of other scenes for 1000 - 2000 pixels etc?
     
  2. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    217
    Likes Received:
    161
    yes you can make with little code.

    let dist = this.scene().path().pathPosition();
    Settings.dist=Math.round(dist);

    if(Settings.dist>0 && Settings.dist<5000){
    let scn = Math.round(Math.random() *9)+1; //scene 1-10 random
    this.scene().addLevel(String(scn));

    if(Settings.dist>5000 && Settings.dist<10000){
    let scn = Math.round(Math.random() *9)+11; //scene 11-20 random
    this.scene().addLevel(String(scn));
     
    PunkPuffin and AaroArts like this.
  3. AaroArts

    AaroArts Miniboss Boxer

    Joined:
    Jun 22, 2016
    Messages:
    1,507
    Likes Received:
    792
    Oh that’s really awesome! Thank you.
    Where do you place this code? Is there a node specific for the World?
     
  4. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    217
    Likes Received:
    161
    use any object, just add this object begining of the game.
     
    AaroArts likes this.
  5. whitedogapp

    whitedogapp Avid Boxer

    Joined:
    Oct 8, 2015
    Messages:
    226
    Likes Received:
    33
    can u show us how it looks like in script
     
  6. Scriv

    Scriv Boxer

    Joined:
    Oct 28, 2018
    Messages:
    41
    Likes Received:
    18
    Weboha- you have just taken the possibilities to the next level with this script! Thank you!

    White dog- load a basic asset.. and delete everything except the start node. Call that asset ‘Level sections’ or something.

    Now from the advanced section of the nodes get a script node and paste weboha’s code into the ‘innit’ section of the code.

    That means it will run on ‘initialisation’ of the ‘Level Sections’ asset.

    Now drag that “Level Sections” asset into your start scene and make sure it’s right at the top of the scene asset list... that means it will run before anything else.


    Take it easy.
     
  7. AaroArts

    AaroArts Miniboss Boxer

    Joined:
    Jun 22, 2016
    Messages:
    1,507
    Likes Received:
    792
    Awesome. Thanks for confirming that.

    Probably a silly question, but what is the ratio of distance (or pixels) to the grid?

    For example if your object starts at (0,0,0) and ends at (0,0,1), is that a distance of 1000?
     

Share This Page