Three.js and Tween.js, chained animation with rotations does not work -


i'm trying move cube first towards camera, turn left, , move forward, right side of screen. i'm building maze turtle move forward , rotate , want use tweenjs animations.

a fiddle here https://jsfiddle.net/edapx/o6mvg0d5/1/

as see, first 2 animation executed, last 1 not move cube expected. i'm chaining animations this:

function testchained(){     var radians = 90 * three.math.deg2rad;      var pos_copy_a = new three.vector3().copy(mesh.position);     var target_a = pos_copy_a.add(new three.vector3(0.0, 0.0, 50.0));     var rotationmatrix_a = new three.matrix4().makerotationy(mesh.rotation.y);     target_a.applymatrix4(rotationmatrix_a);     var = new tween.tween(mesh.position).to(target_a, 900);      var target_b = {y:mesh.rotation.y + radians};     var b = new tween.tween(mesh.rotation).to(target_b, 900);      var pos_copy_c = new three.vector3().copy(mesh.position);     var target_c = pos_copy_c.add(new three.vector3(0.0, 0.0, 50.0));     var rotationmatrix_c = new three.matrix4().makerotationy(mesh.rotation.y);     target_c.applymatrix4(rotationmatrix_c);     var c = new tween.tween(mesh.position).to(target_c, 900);      a.chain(b);     b.chain(c);     a.start(); }; 

am using tween.js wrong?

this is, because set target_c before animations start. so, target_c same target_a. when animation c starts, mesh @ position 0 0 50, target_c 0 0 50, too. so, need set target_c after animation has completed. animation c relies on "result" of previous ones, guess, chaining isn't easy.

in jsfiddle, just wrapped instantiation of animation c complete callback of animation b make work: https://jsfiddle.net/327bclgp/

edited question

what i'm looking called animation relative values. https://github.com/tweenjs/tween.js/blob/master/docs/user_guide.md#relative-values works when piling rotations, mixing rotation , translation tricky. here updated fiddle still not works https://jsfiddle.net/edapx/o6mvg0d5/5/

edited answer

it's not string (string(distance_a.x)), need prefix plus sign make relative: '+' + distance_a.x;

and wouldn't use mesh.rotation.y rotate vector. that's same described above. when set set rotationmatrix_c, mesh.rotation.y still 0. instead, use fix values.

var radians = 90 * three.math.deg2rad; ... var rotationmatrix_c = new three.matrix4().makerotationy(radians); var distance_c = new three.vector3(0.0, 0.0, 50.0); distance_c.applymatrix4(rotationmatrix_c); var target_c = {     x: '+' + distance_c.x,     y: '+' + distance_c.y,     z: '+' + distance_c.z }; 

https://jsfiddle.net/o6mvg0d5/6/

if have more rotations, need sum radians value, e.g. radians += 90 * three.math.deg2rad;


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -