getzel Posted October 8, 2016 Share Posted October 8, 2016 Edit : problem solved, look below ______ lookAt works well on the view. But the parameter rotation doesn't change staying at 0,0,0. And I need it after to calculate the vector forward in local space of a mesh to moveWithCollision : var forwards = new BABYLON.Vector3(parseFloat(Math.sin(character.rotation.y)) / speedCharacter, gravity, parseFloat(Math.cos(character.rotation.y)) / speedCharacter); forwards.negate(); character.moveWithCollisions(forwards); In the playground, I don't know how to display text to debug and Jsfiddle doesn't work so I paste my code here : <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style> #renderCanvas { width: 100%; height: 95%; min-height: 95%; } </style> </head> <body> <div id="info"> aaa </div> <canvas id="renderCanvas"></canvas> <script src="http://cdn.babylonjs.com/2-4/babylon.js"></script> <script> var info = document.getElementById('info'); var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 10, BABYLON.Vector3.Zero(), scene); camera.attachControl(canvas, false); var light = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(0, 100, 100), scene); var cube = BABYLON.Mesh.CreateBox("Box", 1, scene); var cube2 = BABYLON.Mesh.CreateBox("Box2", 1, scene); cube.position.x = -5; var material = new BABYLON.StandardMaterial("default", scene); material.emissiveColor = new BABYLON.Color3(0.3, 0.3, 0.5); cube.material = material; var material2 = new BABYLON.StandardMaterial("default2", scene); material2.emissiveColor = new BABYLON.Color3(0.5, 0.3, 0.3); cube2.material = material2; scene.beforeRender = function() { }; // Render loop var renderLoop = function () { cube.lookAt(cube2.position); cube2.position.z += 0.01; info.innerHTML = cube.rotation; // !!! display 0,0,0 everytime !!! scene.render(); }; // Launch render loop engine.runRenderLoop(renderLoop); </script> </body> </html> Thank you Quote Link to comment Share on other sites More sharing options...
getzel Posted October 8, 2016 Author Share Posted October 8, 2016 There is a topic about that : lookAt changes the rotation to quaternion mode. I try the code and then change my mesh.rotation.x = mesh.rotation.z = 0; He looks to the good direction but only 180°. This function seems to work to retrieve rotation euler : mesh.rotationQuaternion.toEulerAngles(); Quote Link to comment Share on other sites More sharing options...
getzel Posted October 8, 2016 Author Share Posted October 8, 2016 Finally I found a solution without quaternion but trigonometry. This code is to rotate a character on y axis : function mousemovef(){ var pickResult = scene.pick(scene.pointerX, scene.pointerY); if (pickResult.hit) { var pickResultPos.x = pickResult.pickedPoint.x; var pickResultPos.z = pickResult.pickedPoint.z; var diffX = pickResultPos.x - man.position.x; var diffZ = pickResultPos.z - man.position.z; man.rotation.y = Math.atan2(-diffX,-diffZ); }// if result }//mousemovef() window.addEventListener("mousemove", function() { mousemovef(); }); iiceman 1 Quote Link to comment Share on other sites More sharing options...
iiceman Posted October 10, 2016 Share Posted October 10, 2016 Sounds good, maybe you can add a little playground to show how it works, that would be awesome! Quote Link to comment Share on other sites More sharing options...
getzel Posted October 10, 2016 Author Share Posted October 10, 2016 @iiceman Sure ! Here is an example of rotating and moving with the mouse without lookAt : http://www.babylonjs-playground.com/#1JPHAD#1 iiceman and Wingnut 2 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.