at line number 36
if u change
this.tween = this.entity.tween(this.entity.getLocalPosition())
to
this.tween = this.entity.tween(new pc.Vec3(-4,0,0))
entity is not moving…
The reason it “does not work” is because you do not see the result of the tween. The reason it did work in the first case, is because you tweened the position property of the entity directly. In the second case you simply increase the X value of new vector, which is not related to the entity. You want to tween the entity property, or assign that vector to the entity property on tween update.
var from = new pc.Vec3(-4, 0, 0);
var to = new pc.Vec3(4, 0, 0);
var entity = this.entity;
entity.tween(from)
.to(to, 1.0, pc.SineOut)
.on('update', function(dt) {
entity.setPosition(from);
})
.start();
That’s my bad on misunderstanding the tween library. this.entity.getLocalPosition() returns a reference to the local position of the entity so when it gets updated, it moves the entity too.
Using a new pc.Vec3 means that it changes the property of that object and not the local position of the entity.