lazarmitic Posted February 12, 2016 Share Posted February 12, 2016 I'm trying to make camera "shoot" projectile in direction camera is facing, but I can't seem to find camera direction vector. Only vector I managed to find is camera upVector but with only one vector I can't calculate camera direction vector. Any help how to get direction vector, or maybe how to fire projectile from camera in some other way is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
RaananW Posted February 12, 2016 Share Posted February 12, 2016 Hi Lazarmitic, the simplest way would be to use the Ray class (if you don't wanna deal with math too much) - BABYLON.Ray.CreateNewFromTo(camera.position, camera.getTarget()).direction Quote Link to comment Share on other sites More sharing options...
lazarmitic Posted February 12, 2016 Author Share Posted February 12, 2016 Thanks, this will do it Quote Link to comment Share on other sites More sharing options...
jerome Posted February 12, 2016 Share Posted February 12, 2016 maybe the direction vector is simply : camera.getTarget().subtract(camera.position) assuming that getTarget() returns a point in space and not the vector direction you wanted Venerated1 1 Quote Link to comment Share on other sites More sharing options...
Venerated1 Posted March 13, 2017 Share Posted March 13, 2017 camera.getTarget().subtract(camera.position) does give the perfect unit vector that I was looking for... HUGE thanks jerome. my movement looks like this. http://www.babylonjs-playground.com/#1WFOOA#8 Quote Link to comment Share on other sites More sharing options...
coolroar Posted March 7, 2018 Share Posted March 7, 2018 How about: camera.getFrontPosition(1).subtract(camera.position); ? Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 7, 2018 Share Posted March 7, 2018 Hi @coolroar, getFrontPosition(1) will actually do the job, without subtracting the camera's position. This is why it was introduced Quote Link to comment Share on other sites More sharing options...
coolroar Posted March 15, 2018 Share Posted March 15, 2018 Oh -- Handy! Just to be clear: var unitVec= camera.getFrontPosition(1).subtract(camera.position); console.log(unitVec); console.log("Magnitude: " + Math.sqrt(unitVec.x*unitVec.x + unitVec.y*unitVec.y + unitVec.z*unitVec.z)); var bigVec= camera.getFrontPosition(1); console.log(bigVec); console.log("Magnitude: " + Math.sqrt(bigVec.x*bigVec.x + bigVec.y*bigVec.y + bigVec.z*bigVec.z)); 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.