Creating forever

var TileSpawner = pc.createScript('tileSpawner');
TileSpawner.attributes.add('Tile1', { type: 'entity' });
// initialize code called once per entity
TileSpawner.prototype.initialize = function() {

    this.lastTile = new pc.Vec3(0,-0.25,0);
    //'tile:spawn', function (x) {
    for(var i = 0;i<5;i++)
     var rand = Math.floor(Math.random() * 5) +1;
    if(rand == 1){
    }else if(rand == 2){
    else if(rand == 3){
    else if(rand == 4){
    else if(rand == 5){
    else if(rand == 6){

// update code called every frame
TileSpawner.prototype.update = function(dt) { ='Camera');   
        var up = new pc.Vec3(-40,0,0);
        var mid = new pc.Vec3(-40,0,0);
        var down = new pc.Vec3(-40,0,0);
        var position = [up, down,mid,mid,mid,mid, mid];
        var rand = position[Math.floor(Math.random() * position.length)];
        this.lastTile = this.lastTile.add(rand);

TileSpawner.prototype.spawn = function(position){
    // Create an asteroid at (x,y) drifting towards (direction) with (speed) 
    var tile = this.Tile1.clone(); = "newTile";;
    tile.enabled = true;
    return tile;

TileSpawner.prototype.relax = function()
    var player ='Player');
    var newTile ='newTile');

There are 6 tracks in this code. And in this track, I am trying to set one of the 6 tracks to generate random tracks. But it always produces the same track. Whatever track he creates the first time, he always creates the same track and continues to create that piece forever. I want it to create a different piece each time.

Hi @Ozden_Delibas,

It’s a bit difficult to follow your code out of context, not sure what the issue is.

In any case, here is an example on creating a procedural level, you can check the logic on how the loop works:

I’m guessing that there are multiple children under the entity that this script is on called parkur-1 to parkur-7

However, since you are using, it’s going to find the first instance in the WHOLE scene, not the child entities.

Try using this.entity.findByName instead which will look for Entities under the current Entity.


Will try