[SOLVED] Errors that I can't fix make my game unplayable :(

https://playcanvas.com/editor/scene/1636550

So. My game broke. (sort of). Ever since i made my gun script and enemy script, anytime the bullet collided with another entity or enemy, i would get an error. I would ignore this as i thought it was some bug that would be fixed sooner or later. But now, i have tried to add an enemy spawner that periodically spawns enemies. But every time the enemies are meant to spawn, 2 things happen: I get a ton of errors not of my doing and 2. The fps drops significantly. Here is the enemy spawner script.

var EnemySpawner = pc.createScript('enemySpawner');
EnemySpawner.attributes.add('enemy1', {
    type: 'entity',
});
EnemySpawner.attributes.add('enemy2', {
    type: 'entity',
});

// initialize code called once per entity
EnemySpawner.prototype.initialize = function() {
    //set initial time
    this.time = 0;
    this.spawnNext = 1;
    this.spawned = 0;
};

// update code called every frame
EnemySpawner.prototype.update = function(dt) {
    // update time
    this.time += dt;
    if (this.time >= this.spawnNext) {
        this.spawnNext = this.time + 1;
        this.spawned += 1;
        if (this.spawned <= 25) {
            console.log("spawn1");
            this.spawnEnemy1();
        } else {
            console.log("spawn2");
            this.spawnEnemy2();
        }
    }
};

EnemySpawner.prototype.spawnEnemy1 = function(dt){
    enemy = this.enemy1.clone;
    this.app.root.addChild(enemy);
    enemy.enabled = true;
};

EnemySpawner.prototype.spawnEnemy2 = function(dt){
    enemy = this.enemy2.clone;
    this.app.root.addChild(enemy);
    enemy.enabled = true;
};

https://playcanvas.com/project/1027777/overview/idk-at-this-point
BTW i am working in branch “AM.” The main branch is completely useless.

Hi @almish_subuk!

I see some problems in your project.

The script on your spawned enemies has a problem.

image

This is probably because you have two scripts with the same name, so you have to rename your script and add this ‘new’ script to your enemies.

image

You also define enemy not correct, but I’m not sure if that’s a reason for the other errors.

image

On line 39 and 45 I would start with var enemy instead of just enemy and clone should be clone().

I fixed the problems you mentioned, and the spawner is working fine and the frame drops are no more. However there is still one problem, as when my bullet collides with the enemies, they dissapears but an error shows up that has something to do with the games internal coding. Should i put this in bugs and feedback? also i gave you admin permissions so you can look at branch “am” if you want to look furhter into the pyhsics errors.

1 Like

I changed your bullet script and replaced onContact with onCollisionStart.

Now the error is gone.

ohhhh. thanks man! This error was really annoying but thanks to you its gone! thanks!

1 Like