Tween not moving

I have a small script where I have a list of vrc3, and I need to have an object following that route.
I am using Tween lib in order to do that, but somehow they are not moving, am I using this lib correctly?

Looks like you haven’t called start() on the tween.

From the tutorial: https://developer.playcanvas.com/en/tutorials/tweening/

this.entity
.tween(this.entity.getLocalPosition())
.to(new pc.Vec3(4, 0, 0), 1.0, pc.SineOut)
.loop(true)
.yoyo(true)
.start();

Now I am calling start(), but it’s still the same except tween register that animation is completed objects never moved from place
On console, it says the same vector3 position, but somehow it completes without moving


How often is moved called? Do the objects have rigid bodies?

There is no rigid bodies in project
Called only once per point

Have you tried tweening getLocalPosition() instead?

@eproasim is correct, due to the way the tween works, it directly modifies the vector reference returned from getLocalPosition() which is how it ‘moves’.

Using getPosition() returns a temp vector that is not used for the entity’s transformation matrix.

TLDR, use localPosition

    this.tween = this.entity.tween(this.entity.getLocalPosition())
    .to(this.positions[count], 1, pc.Linear)
    .delay(0)
    .loop(false)
    .yoyo(false)
    .on('complete', function () {
        count++;
        CheckPosition=true;
        console.log('tween completed');
    }).start();
1 Like

It’s working now, but only on one instance of the object.
I have 6 racers with, same script but only one of them is doing animation

What do you mean? All 6 did the first tween as the code in the project and the script called tween only on one specific entity in the update loop once the previous tween has ended

yes, I set the project public again If anyone wants to check
Same script , but only one of them is doing animation

Fixed in this fork: https://playcanvas.com/editor/scene/1102340

The issue was that Racer.js was using global variables instead of variables that were scoped to each script instance.

I’ve now modified it so that it uses properly scoped variables :slight_smile:

You are right , can you please delete that copy of the project ,since this is for company i am working for :slight_smile:
Thank you so much for the help , this lib is amazing :slight_smile:

Done

Yep. Super useful.

While you are all happy with the tween library, I figured I’d pass this little code snippet along that someone else posted for me a while back. I find it super useful. He called it a “Null” Tween. The tween itself doesn’t “tween” anything. But the time it takes to execute can be used to trigger the execution of some other instructions after the tween has complete. I find it pretty handy.

this.app.tween({}).to({}, 1, pc.Linear)
.on('complete', function() {
 // do whatever here
 }, this).start();
3 Likes