Search code examples
javascriptthree.jstween

tweenjs always starts at 0?


I'm using this code to rotate a plane with threejs,But the tween always starts at 0, It appears to be ignoring the initial value (a) althought when I print it in the console it is ok.

For example

I want a tween from 40 to 60, but this code is always going from 0 to 60.

a = {rotationY:plane.rotation.y};
b = json["rooms"][currentRoom]["camera"]; //{"rotationY":60}
var tween = new TWEEN.Tween(a)
        .to(b, 500)
        .easing( TWEEN.Easing.Quartic.Out )
        .onUpdate(function(){
            plane.rotation.y = (this.rotationY*2*Math.PI)/360;
        });

tween.start();

Solution

  • That was a really stupid mistake on my side...

    var position = {rotationY:(plane.rotation.y*360/(2*Math.PI))};
    var target = json["rooms"][currentRoom]["camera"];
    var tween = new TWEEN.Tween(position)
                .to(target, 500)
                .easing( TWEEN.Easing.Quartic.Out )
                .onUpdate(function(){
                    plane.rotation.y = (this.rotationY*2*Math.PI)/360;
    });
    tween.start();
    

    The tween was created with a initial value in radiants and a target set in degrees...