I am working on making the movements of my cubes smoother, since right now I only have them changing position with the setPosition(). The program runs fine, but the cube does not move when clicked. I’m not sure where the issue is.
Project Editor: PlayCanvas | HTML5 Game Engine
var Cube = pc.createScript('cube');
Cube.attributes.add('setPosition', { type: 'vec3' });
Cube.attributes.add('viewPosition', { type: 'vec3' });
// initialize code called once per entity
Cube.prototype.initialize = function() {
this.objName = this.entity.name;
this.app.on('update:position', this.onUpdatePosition, this);
this.entity.on('destroy', function() {
this.app.off('update:position', this.onUpdatePosition, this);
}, this);
};
// update code called every frame
Cube.prototype.onUpdatePosition = function(name) {
if (this.objName === name) {
//this.entity.setPosition(this.viewPosition);
this.entity.tween(this.setPosition).to(this.viewPosition, 1 , pc.SineOut);
} else {
this.entity.setPosition(this.setPosition);
}
};