Animation for TransformNode

Hi,
a question, How to write an animation (rotate) for transform node.
My code is here.

  const [rootNode, setRootNode] = useState<TransformNode>();
  const [animRotateRootNode, setAnimRotateRootNode] = useState<any>();
....
if (engine) {
      const scene = new Scene(engine);
      setScene(scene);

      const rootNode = new TransformNode('Root Container', scene);
      setRootNode(rootNode);
  
      var animRotateRootNode = Animation.CreateAndStartAnimation("animRotateRootNode", 
         rootNode, "rotate", 30, 600,
         rootNode.rotate, rootNode.rotate( Vector3.Down(), Math.PI));
      animRotateRootNode.loopAnimation = false;
      animRotateRootNode.disposeOnEnd = false;
      setAnimRotateRootNode(animRotateRootNode);

But I get :

TypeError: null is not an object (evaluating 'animRotateRootNode.loopAnimation = false')

Heya, there’s a few probs with the params being passed. The 3rd param “targetProperty” should be a property, not a function. And the “to” and “from” params should be the starting and end values for that property. Here’s a PG animating the property rotationQuaternion for example. :slight_smile:

1 Like

thanks

very strange, according to this method, the following code no longer works:

rootNode.rotate(Vector3.Down(), event.movementX * 0.005);

So the rotate function is setting the rotationQuaternion property to the needed value to rotate the node but CreateAndStartAnimation is causing that same property to be set to different values (based on the to and from params).

Are you trying to use animation to do something like, rotate 180 degrees around the y axis from the current rotation?