Hello! I’m needing help because the ground will not move (like it should/looping). I’m confused why it didn’t work with the script that was given to me. I would like to fix the problem, however I have no clue what the problem even is.
Link to editor: https://playcanvas.com/editor/project/1321966
Code used:
var PlatformMovement = pc.createScript('platformMovement');
// initialize code called once per entity
PlatformMovement.prototype.initialize = function () {
this.speed = -6;
this.parent = this.entity.parent;
this.childCount = this.parent.children.length;
};
// update code called every frame
PlatformMovement.prototype.update = function (dt) {
let x = this.entity.getLocalPosition().x + this.speed * dt;
this.entity.setLocalPosition(x, this.entity.getLocalPosition().y, this.entity.getLocalPosition().z);
};
PlatformMovement.prototype.postUpdate = function (dt) {
let x = this.entity.getLocalPosition().x;
if (x <= -14) {
x = this.parent.children[this.childCount - 1].getLocalPosition().x + 2;
this.entity.reparent(this.parent);
this.entity.setLocalPosition(x, this.entity.getLocalPosition().y, this.entity.getLocalPosition().z);
}
};