hit2501 Posted March 24, 2015 Share Posted March 24, 2015 I just want to ask if anyone knows where can I find a tutorial or something similar to make a character move within a stage. I have already made the stage and the character is imported from blender with animation (walking) and I can make him walk but stays in the same place. I tried to follow the advices in:http://www.spritehand.com/2014/08/babylonjs-physics-and-character.html but is advanced for me. Thank you very much. Quote Link to comment Share on other sites More sharing options...
MarianG Posted March 24, 2015 Share Posted March 24, 2015 Here are a very good example, and easy to understand. http://www.castorengine.com/babylon/moveCharacter/ Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 24, 2015 Share Posted March 24, 2015 And here: http://playground.babylonjs.com/#2CPTBX (wasd keys) You might need to click on the canvas, first. This is a job for the world famous mesh.moveWithCollisions() function. You'll see it a couple times, in the code. But I'm missing a transform after the rotations. SOMETHING like this: var invMatrix = new BABYLON.Matrix(); box.getWorldMatrix().invertToRef(invMatrix); var direction = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(0, 0, 1), invMatrix); direction.normalize(); That's not correct, but its possibly in the ballpark. After a rotation, a new forward/backward direction must be established and applied. I don't know how, yet. And even once I do have a direction, I don't know what the hell to do with it. As you can see in the demo... after a rotation, the forward/backward translations are still worldSpace +/- z-axis. They should probably be LOCALspace +/- z-axis. There are others nearby that can fix my demo in a heartbeat, and then you'll be ready to do some character walking! yay! webdva 1 Quote Link to comment Share on other sites More sharing options...
hit2501 Posted March 24, 2015 Author Share Posted March 24, 2015 Thank you both. These examples are just what I need. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
hit2501 Posted March 26, 2015 Author Share Posted March 26, 2015 I tried with the example of Wingut and works fine with animations imported from Blender but I only can move the character and after that the animation runs, is there any way to do both at once? Here's the code Im using (I put the animations in case "W" to go forward and case "S" to move back):BABYLON.SceneLoader.ImportMesh("", "Babylon/", "policewoman01.babylon", scene, function (newMeshes, particleSystems, skeletons) { var policewoman = scene.getMeshByName("policewoman"); //policewoman.position.y = .51; policewoman.position = new BABYLON.Vector3(0, 0, 0); // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene); //camera.position = policewoman.position; var moveVector = new BABYLON.Vector3(0, 0, 0); var movestep = .05; var rotstep = .05; var onKeyDown = function(event) { var key = event.keyCode; var ch = String.fromCharCode(key); switch (ch) { case "W": moveVector.z = movestep; policewoman.moveWithCollisions(moveVector); scene.beginAnimation(skeletons[0], 0, 30, false, 1.0); break; case "A": policewoman.rotate(BABYLON.Axis.Y, -rotstep, BABYLON.Space.LOCAL); break; case "S": moveVector.z = -movestep; policewoman.moveWithCollisions(moveVector); scene.beginAnimation(skeletons[0], 31, 60, false, 1.0); break; case "D": policewoman.rotate(BABYLON.Axis.Y, rotstep, BABYLON.Space.LOCAL); break; } }; var onKeyUp = function(event) { /* var key = event.keyCode; var ch = String.fromCharCode(key); switch (key) { case 16: speed = 5; break; } */ }; document.addEventListener("keydown", onKeyDown, false); document.addEventListener("keyup", onKeyUp, false); }); scene.registerBeforeRender(function() { /* moveVector.z += step; box.moveWithCollisions(moveVector); if (box.position.z > 2 || box.position.z < -2) { step *=-1; } */ }); return scene; }; var scene = createScene(); engine.runRenderLoop(function () { scene.render(); }); window.addEventListener("resize", function () { engine.resize(); }); </script>Sorry for the inconvenience, this is something that interests me a lot. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.