I’m updating a local y-axis from the local position via lerp and apply it to the target entity.
Somehow the y-axis from the world position is slightly changed after updating the local y-axis.
Is it normal behavior?
Main.prototype.initialize = function() {
this.app.on("animation:window", (target) => {
this.time = 0;
this.duration = 5;
this.windowEntity = this.app.root.findByName("Window_Glass");
this.entityLocalPosition = this.windowEntity.getLocalPosition();
this.newLocalPosition = new pc.Vec3(197.002, 100.00, 0);
this.yAxis = this.entityLocalPosition.y;
console.log('World Position : ', this.windowEntity.getPosition(), ', Local Position : ', this.entityLocalPosition);
});
};
// update code called every frame
Main.prototype.update = function(dt) {
if(this.entityLocalPosition && this.newLocalPosition) {
this.time += (dt/1.5);
if (this.time > this.duration) {
this.time -= this.duration;
}
var alpha = this.time / this.duration;
this.yAxis = pc.math.lerp(this.yAxis, this.newLocalPosition.y, alpha);
if(Math.round(this.yAxis * 10)/10 === Math.round(this.newLocalPosition.y *10)/10 ) {
console.log('window down completed');
console.log('World Position : ', this.windowEntity.getPosition(), ', Local Position : ', this.entityLocalPosition);
this.newLocalPosition = null;
} else {
this.windowEntity.setLocalPosition(this.entityLocalPosition.x, this.yAxis, this.entityLocalPosition.z);
}
}
};