So I have several moving platforms in my game and if I try giving each of them a their own script the game starts lagging. so I tried making a singular script for all of them. I gave the blocks number tags and tried both just set the "find by tag " with number and number turned to string
I did the following:
var Translate = pc.createScript('translate');
// initialize code called once per entity
Translate.prototype.initialize = function() {
for(var j = 0; j < 10; j++){
var broj= j.toString();
var blocks = this.app.root.findByTag(broj);
this.startingPositions = [];
this.startingRotations = [];
for(var i = 0; i < blocks.length; i++){
this.startingPositions.push(blocks[i].getLocalPosition().clone());
this.startingRotations.push(blocks[i].getLocalRotation().clone());
}
}
};
var br= 1;
// update code called every frame
Translate.prototype.update = function(dt) {
var rnd= pc.math.random(0.0001, br/100);
var base = -0.05;
var add =base-rnd;
this.entity.translateLocal(0,add,0);
var poz = this.entity.getPosition().y;
if(poz <-26){
for(var j = 0; j < 10; j++){
var broj= j.toString();
var blocks = this.app.root.findByTag(broj);
for(var i = 0; i < blocks.length; i++){
blocks[i].rigidbody.teleport(this.startingPositions[i],this.startingRotations[i]);
blocks[i].rigidbody.linearVelocity = pc.Vec3.ZERO;
blocks[i].rigidbody.angularVelocity = pc.Vec3.ZERO;
br=br+1;
}
}
}
};
// swap method called for script hot-reloading
// inherit your script state here
// Translate.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/
Does anyone have any suggestion on what I could try? it would be greatly appreciated
also here’s the entire project
https://playcanvas.com/project/591390/overview/keep-climbing
EDIT: I tried using FindByTag(“xyz” || “zyx”) but it also didn’t work