So noticed this when testing some stuff, the y coordinate from getting the entity.position always seems to be off by 0.0001###########.
After trying to set the position of the entity in the editor I also noticed the fact that the coordinates for position also get rounded to the 3rd decimal point and trying to set the position using setPosition results in it overflowing into 4.93431091308589e-7.
This is the script I used for a local entity spawned in-game to test with;
var Movement = pc.createScript('movement');
// initialize code called once per entity
Movement.prototype.initialize = function() {
console.log("Test Mouse Register");
this.pos = new pc.Vec3();
this.app.mouse.on (pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
};
Movement.prototype.onMouseMove = function (event){
//var test1 = this.entity.position.y;
var test1 = this.entity.position.y; // off by 0.0001############
console.log(test1);
var test2 = this.entity.position.y - 0.0001; // Overflows
console.log(test2);
};
Can you please explain on why it only affects the Y coordinate and not also the X and Z coordinates, seems weird its like that and even trying to set it perfectly to 0 will result in it rounding to 0.0001 for some reason. Don’t think changing how small the decimal place is would also really change anything. (I’m assuming 0.0001 is less then 1/10th of a pixel)
I should probably point out that this.entity.position is not API. You should use this.entity.getPosition and this.entity.setPosition instead. I’ll leave @max to continue the conversation on rounding - I have no idea about that.