Jump to content

Multile animations doesnt work on more than 1 object


swat0284
 Share

Recommended Posts

Hello i try to run 5 animations on 5 diffrent models but i have an error:
 

Uncaught TypeError: Cannot read property 'frame' of undefined
    at i._interpolate (babylon.js:18)
    at i.animate (babylon.js:19)
    at e._animate (babylon.js:19)
    at i._animate (babylon.js:12)
    at i.render (babylon.js:12)
    at main.js:33
    at n._renderLoop (babylon.js:4)

My code is very silmpy

function CreateAnimation(index)
{	
	
	var moveAnimation = new BABYLON.Animation("moveAnimation", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); //tworzenie animacji przemieszczania sie
    var moveKeys = [];
	var moveLenght = 0;
	console.log(checkpointsPositions[index].length +"checkpoints lenght");
	for(var i = 0 ; i < checkpointsPositions[index].length ; i++)
	{
		//.toFixed(0)
    moveKeys.push({ frame: (jsonObjectResults.points[licznik].time)*30, value: (checkpointsPositions[index][i].position) });
	console.log(checkpointsPositions[index][i].position + " +++ " + (jsonObjectResults.points[licznik].time).toFixed(0)*30);
	console.log("Licznik " + licznik);
	moveLenght++;
	licznik++;
	}
	licznik++;
    moveAnimation.setKeys(moveKeys);
    players[index].animations.push(moveAnimation);
	scene.beginAnimation(players[index], 0, jsonObjectResults.points[licznik-2].time*30, true);
	
}

I start the code by createAnimation(index of mesh) and when i run it once it works but when i run it more than one it doesnt work

Link to comment
Share on other sites

Hi,

I am not sure I get what you are trying to do. In each run of the for loop, you add further keys to the animation, and then you push the same object to the player in a specific index. You also don't reset the array, you simply add further objects. when you "setKeys" again, you "remove" the old keys, and then set the new ones. And, as far as I know (and this is probably the answer to the entire question) - animations cannot be shares between objects. Animation keys can be shared between animation objects, if you want to reuse. But you need an animation object per mesh.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...