I'm trying to animate a smooth moving of an entity, when appending it to another parent in the scene.
There are a few plugins out there to animate a change of the position itself, but not when the position stays the same, but the parent is changing.
I need this, because I have different "spots" defined, where the entity can be. Now I want to put the entity into one of these spots, so I don't have to calculate the new position of the entity. Without animation, that concept works perfect.
My current resolution for the animation is the following:
- iterate through all current parents of the entity and sum the position vectors of these elements
- iterate through all the parents and the new parent itself and sum the position vectors of these elements
- subtract the two calculated vectors
- append the entity to the new parent and add an animation with
from
= the resulting offset vector andto="0 0 0"
Works, but in some frames the element flickers, because it is first appended to the new parent (position="0 0 0"
, so exatly on the new parent), it gets drawn, and then the animation starts with the from
placing it at the old position and moving it back to "0 0 0"
.
I built a jsfiddle, which shows the problem: https://jsfiddle.net/fshqghxt/
Can someone help me out on fixing this? I'm also open for completely different concepts. Thank you in advance!