Hiya,
I have a script which I’ve taken from some where else. I would like an object to move from one position to another on a button click. This script does do that… however it then snaps back to the original position on completion. Is there an easy way to make it hold once it goes to it’s new position.
thanks!
var ButtonTween = pc.createScript('buttonTween');
ButtonTween.attributes.add('button', {
type: 'entity',
title: 'Button',
description: 'The Button being clicked on.'
});
ButtonTween.attributes.add('tweenObject', {
type: 'entity',
title: 'Object',
description: 'The Object to tween'
});
ButtonTween.prototype.initialize = function() {
this.origPos = this.tweenObject.getLocalPosition().clone();
this.origRot = this.tweenObject.getLocalEulerAngles().clone();
this.targetPos = new pc.Vec3(4.0, 3.5, -4.0);
this.targetRot = new pc.Vec3(-30, 135, 0);
this.targetPosTween = this.tweenObject.tween(this.tweenObject.getLocalPosition())
.to(this.targetPos, 2.0, pc.Linear);
this.targetRotTween = this.tweenObject.tween(this.tweenObject.getLocalEulerAngles())
.rotate(this.targetRot, 2.0, pc.Linear);
this.button.button.on('click', this.onButtonClick, this);
};
ButtonTween.prototype.onButtonClick = function() {
if(!this.completed) {
this.targetPosTween.start();
this.targetRotTween.start();
this.completed = true;
}
};