Jump to content

Preserve a mesh position reference during animation


svatopluk
 Share

Recommended Posts

Hello. I have the following code:

var m = new BABYLON.Mesh.CreateBox('m', 1, scene);
m.position = new BABYLON.Vector3.Zero();
camera.lockedTarget = m.position;
var myAnimation = new BABYLON.Animation("anim", "position", 20, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
var keys = [];
keys.push({
	frame: 0,
	value: m.position,
});
keys.push({
	frame: 20,
	value: new BABYLON.Vector3(m.position.x + 10, 0, m.position.z + 10),
});
myAnimation.setKeys(keys);
m.animations.push(myAnimation);
scene.beginAnimation(m, 0, 20);

The problem is that the position of mesh is changed but the camera lockedTarget is still at 0,0,0. I suspect that during the animation the m.position vector is overriden by animation inserting a new Vector3() at the place of m.position. So the camera.lockedTarget is pointing to that old(first) reference of m.position.

I'm I right about this? Is there a way to sidestep this problem?

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...