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();
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
Kapture 2021-03-02 at 15.49.41
You are right , can you please delete that copy of the project ,since this is for company i am working for
Thank you so much for the help , this lib is amazing
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();