I ran into something odd today and am not sure if it is a bug or if I just don’t understand the function and use properly. The short description is that the statement:
console.log(‘After location’, this.CopterSphere.getPosition());
updates the reposit variable the same as:
reposit = this.CopterSphere.getPosition();
The longer version is that the entity CopterSphere is parented to an an entity Copter. I reposition Copter after having previously set the Vec3 variable, reposit to CopterSphere’s position. At this point in time, reposit still holds the old values for CopterSphere’s location. But if I call a console.log statement that gets the CopterSphere location using .getPosition, the variable reposit gets updated?!?!?
I’ve had no problem working around this, now that I understand what is going on. But I was surprised to see that my working script broke when I remarked out all of my console.log statements. It turns out I had failed to update the reposit variable and the console.log statement was covering up my mistake.
So is this normal functioning? I’m just beginning to learn PlayCanvas and found this behavior very surprising and not intuitive at all.
Thanks!
…
master = this.Copter.getPosition();
target = this.PivotMarker.getPosition();
reposit = this.CopterSphere.getPosition();
console.log('original CopterNull Pos', master);
shiftAmt = master.sub(target);
console.log('target Null Pos', target);
console.log('Before location.', reposit);
console.log('Shift Amount', shiftAmt);
this.Copter.setPosition(target);
//console.log('After location', this.CopterSphere.getPosition());
reposit = this.CopterSphere.getPosition();
this.CopterSphere.setPosition(reposit.add(shiftAmt));
console.log('After location2', this.CopterSphere.getPosition());
this.Copter.script.rotate.orbitSensitivity = 0.25;
…