Hi,
I’m attempting to dynamically create a platform with infinite movement. I’ve been following the Infinity Runner Tutorial, and you can find the project here. The project is functioning as intended.
While going through the code, I noticed a part where the platform is removed when it reaches a certain point, and then it’s added to the start again using the following line:
x = this.parent.children[this.childCount - 1].getLocalPosition().x + 2;
Instead of adding a fixed value of 2 to the code, I’d like to add it to the size of the entity so that I can use the same code for a much wider platform.
Note: The model of platforms cannot be accessed using this.entity.model;
If you take a look at the project, you’ll notice that I’ve attached a script to the ground entity, which serves as the template. The code I use to obtain its size is as follows:
var meshInstances = this.entity.children[0].render.meshInstances;
if (meshInstances.length > 0) {
var bbox = new pc.BoundingBox();
bbox.copy(meshInstances[0].aabb);
for (var i = 1; i < meshInstances.length; i++) {
bbox.add(meshInstances[i].aabb);
}
this.size = bbox.halfExtents.x;
}
This approach may vary if the platform structure is different, such as when the render component is in the 2nd child or parent component. Is there a way to address this variation? Can I directly retrieve the size of the template?