I don’t understand why my Vec3 is losing its value.
The entities are generated in code and given a position. When the entity is initialised, it stores its position in ‘originalPosition’
When the entity is clicked it is detected with a raycast and calls the entities clicked() function. When that function is called the Vec3 originalPosition has changed to (0,0,0)
pc.script.create('selected', function (app) {
var originalPosition = new pc.Vec3();
// Creates a new Selected instance
var Selected = function (entity) {
this.entity = entity;
};
Selected.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
originalPosition = this.entity.getPosition();
console.log("originalPositionInit" + originalPosition + this.entity.getGuid());
},
clicked: function(){
console.log("originalPositionClicked" + originalPosition + this.entity.getGuid());
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
}
};
return Selected;
});