Hersir Posted May 15, 2017 Share Posted May 15, 2017 Hi, I am trying to move mesh relative to ArcRotateCamera alpha value. Basically it should move the same direction as mouse is moving (up, down, left, right) , works fine with 0 angle but different angles need to flip x/z and change their directions. What the best way to calculate direction vector from angle and 0 angle direction? Working example: http://www.babylonjs-playground.com/#W8MYRB#7 (angle 0) Not working: http://www.babylonjs-playground.com/#W8MYRB#10 (angle 55) I tried to rotate vector using: const matrix = BABYLON.Matrix.RotationAxis(BABYLON.Axis.Y, camera.alpha); const movement = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(x, 0, z), matrix); Quote Link to comment Share on other sites More sharing options...
Hersir Posted May 15, 2017 Author Share Posted May 15, 2017 Ok found how to fix: const matrix = BABYLON.Matrix.RotationAxis(BABYLON.Axis.Y, Math.PI - camera.alpha); const movement = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(x * -1, 0, z * -1), matrix); Will need to study a bit matrices to understand why Math.PI - camera.alpha was needed Working version: http://www.babylonjs-playground.com/#W8MYRB#11 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.