devbot Posted September 11, 2015 Share Posted September 11, 2015 I've been scratching my head a bit on this and feel it should be much easier than it is turning out to be. I have a freeCamera in a scene which can be controlled with WASD.What I also have is a UI with the WASD keys which light up when the user presses those keys. Lastly I'm trying to have those keys mousedown to also move the free camera in the same way they keys do. What I've been trying to work with is something along the lines ofcase: "forward"freeCamera.cameraDirection += BABYLON.Vector3.Cross(freeCamera.position,freeCamera.rotation) * speed;break;case: "back"freeCamera.cameraDirection -= BABYLON.Vector3.Cross(freeCamera.position,freeCamera.rotation) * speed;break; And about 50 variations of that. I started out with simply assigning each key to an axis and moving along it, which is all well and good until you rotate the camera. Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 11, 2015 Share Posted September 11, 2015 You know, that you can assign new buttons to the camera like: camera.keysUp.push(87); // "w" So try out this one: http://playground.babylonjs.com/#2FSOZ The advantage would be: The rotational calculation is done for you. Only for rolling it seems the free camera is missing a movement? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted September 11, 2015 Share Posted September 11, 2015 Hi guys. Many folk parent the camera to an invisible mesh, and then do all their orientations and translations on the parent "camera gizmo". *shrug* An option. Ped-up and ped-down seem like important camera movements (up and down the Y axis)... but not found on a default free camera. I wired those actions to control-upcursor and control-downcursor, in a project once (plotting vertices in space). I didn't modify the free camera itself. I just built my own ped-up/down funcs that did the job. You guys can do the same for spinning the camera around z-axis (rolling)... as needed. Also... umm... devbot... think about continuously using cam.setTarget(something)... on every frame. Maybe even better... free camera is a subClass of TargetCamera... which also has a .lockedTarget property. The free camera inherits that property, of course. These might be usable features for this issue, too. Party on! Ahiru 1 Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 11, 2015 Share Posted September 11, 2015 Thanks - the .lockedTarget is helpful! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
devbot Posted September 14, 2015 Author Share Posted September 14, 2015 Thanks for the input, I saw this thread which lead me to this result. function drive_camera(axis){ var move_direction = BABYLON.Vector3.TransformNormal(axis, freeCamera.getWorldMatrix()); freeCamera.cameraDirection = move_direction } Where axis is a variation of BABYLON.Vector3(1, 0, 0); depending on the button clicked/mousedown (WASD) ThorJohn and Wingnut 1 1 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.