Jump to content

The problem with animation


DigitalHilsone
 Share

Recommended Posts

We have the following hours:



var createScene = function () {
var scene = new BABYLON.Scene(engine);

// setup environment
var light0 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 10, 20), scene);
var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 0, new BABYLON.Vector3(10, 10, 0), scene);
camera.setPosition(new BABYLON.Vector3(-10, -10, -30));
camera.attachControl(canvas, true);

// Impact impostor
var impact = BABYLON.Mesh.CreatePlane("impact", 1, scene);
impact.material = new BABYLON.StandardMaterial("impactMat", scene);
impact.material.diffuseTexture = new BABYLON.Texture("textures/impact.png", scene);
impact.material.diffuseTexture.hasAlpha = true;
impact.position = new BABYLON.Vector3(0, 0, -0.1);

//Wall
var wall = BABYLON.Mesh.CreatePlane("wall", 20.0, scene);
wall.material = new BABYLON.StandardMaterial("wallMat", scene);
wall.material.emissiveColor = new BABYLON.Color3(0.5, 1, 0.5);

//When pointer down event is raised
scene.onPointerDown = function (evt, pickResult) {
// if the click hits the ground object, we change the impact position
if (pickResult.hit) {
BABYLON.Animation.CreateAndStartAnimation("anim", impact, "position", 30, 120,
impact.position, impact.position.add(new BABYLON.Vector3(pickResult.pickedPoint.x, pickResult.pickedPoint.y, 0)));
}
};

return scene;
}


Did not get to stop the animation at its conclusion. Animation is cyclical. I need to make it a single. Help me with this.

Link to comment
Share on other sites

Hi, welcome to the forum.

 

From the Animation class API...

    static ANIMATIONLOOPMODE_RELATIVE : number    The animation loops but doesn't reset values and continues animation with values of the previous ending animation    static ANIMATIONLOOPMODE_CYCLE : number    The animation restarts with the inital values    static ANIMATIONLOOPMODE_CONSTANT : number    The animation keeps its final value i.e stopped

The "0" at the end of your CreateAndStartAnimation call... is the optional loopMode parameter.

 

So... I think you can change that last "0"... into

 

BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT

 

Again, delete the zero and replace with the above line.  Should work.  :)  Report back, good luck.

Link to comment
Share on other sites

Wingnut, write the function like this: 
        if (pickResult.hit) {BABYLON.Animation.CreateAndStartAnimation("anim", impact, "position", 30, 30,impact.position, impact.position.add(new BABYLON.Vector3(pickResult.pickedPoint.x, pickResult.pickedPoint.y, 0)), 0);        }

Now the condition is met. Thank you for your help!

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