Forum

Use actions in animation to move object

05 March 2018 15:29
Hello. I'm quite new in b4w and want to know how to change position (using JS) after animation is done. I explain my actual scenario so you can identify the problem:

A 1 frame timeline with no actions assigned to objects so they stay stopped on begin.
In my scene there are 10 boxes each called BLOCK001, BLOCK002 and so on (they all have active dynamic geometry and can be moved via code).
An action called "jump" with activated [F] so datablock is saved even with no active uses.
On javascript i have set up the anim and called it using:

m_animation.apply(target_object,"jump");
m_animation.play(target_object,callback_after_jumping);

function callback_after_jumping(object_to_move) {
	m_trans.move_local(object_to_move, 2, 0, 0);
}


I want it to move 2 units through the X axis after finishing animation, but it seems to reset position to 0,0,0 each time i play the animation so it always begins at it initial position. How can i make it animate, update starting position, and animate again starting from that new coordinates?
05 March 2018 22:29
Hello! And welcome to our forum!

Did you try parenting? You can set some empty object as parent (Ctrl+P) of the cube and then move this empty. In this case cube will be animated in local space and no reset will happen.
Alexander (Blend4Web Team)
twitter
06 March 2018 13:10
If i add a parent it acts the same way:

If i animate the parent one time it starts from its starting position but when i start the animation for a second time it begins from its original position again and does not stay on the last x,y,z it ended after animation. And its child follow him.

If i animate the child it happens the same: it always begin from its starting point after i restart anim. Do i have to change behaviour? I defined AB_FINISH_STOP. Or maybe i have to move manually the parent after animation has finished?
08 March 2018 02:17
If i animate the parent one time it starts from its starting position but when i start the animation for a second time it begins from its original position again and does not stay on the last x,y,z it ended after animation. And its child follow him.
You don't need to animate a parent. You should change its position using javascript or Logic Nodes. You should understand that the animated translation and the actual translation is the same attribute of the object. If you animated any object, you always have the first and the last frame of animation. And each frame between has some value of animated attribute. it is not addable, it is constant for each animation frame. So the answer is to make seamless animatioin of jumping for child and move the origin procedurally.
Alexander (Blend4Web Team)
twitter
 
Please register or log in to leave a reply.