Dad72 Posted September 2, 2015 Share Posted September 2, 2015 Hi, How to make an object can always be placed before the camera with respect to its rotation. Thank you Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 2, 2015 Author Share Posted September 2, 2015 I just found the solution (I think). var getPositionObjet = function() { var camera = scene.activeCamera; var forward = new BABYLON.Vector3(camera.position.x + 7, camera.position.y, camera.position.z + 7); return forward; }; Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 2, 2015 Author Share Posted September 2, 2015 Not in this is made this. I do not see how. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 2, 2015 Share Posted September 2, 2015 Object can be defined as child of the camera and then you can just move it to Z axis: mesh.parent = camera;mesh.position = new BABYLON.Vector3(0, 0, 10); Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 2, 2015 Author Share Posted September 2, 2015 Yes, this work. Thank you DK Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 2, 2015 Author Share Posted September 2, 2015 Not it will not work correctly. I have a menu that allows me to add objects and I wish it were always facing the camera regardless of its position and rotation. The object is attached to the camera, thus is moving with the camera. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 2, 2015 Share Posted September 2, 2015 Yep so I do not get what you want to achieve. can you create a small playground to iterate on it? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 2, 2015 Author Share Posted September 2, 2015 En gros, je veux que en ajoutant un objet dynamiquement à la scene suite un un clique dans un menu, l'objet ce place devant la camera quelque soit la position et la rotation de cette cameraUn cube par exemple, quand je clique sur l'item pour créer un cube, je veux qu'il soit créer face a la camera. actuellement je récupère la position de la camera puis l'objet se place à cette position, mais moi j'aimerais qu'il ce place devant, genre a 7, 10 unité en face d'elle et ce quelque soit ou la camera est en position et rotation (Z sur un axe local donc). Peut être que une fonction vector3 camera.position.Forward(num); avec axe local aiderais de façons a avoir toujours une valeur le long de cette axe. si je met 10 dans num de forward mon mesh seras a 10 en face de la camera. De cette façons je pourrais faire facilement:mesh.position = camera.position.Forward(10); //déplacerais le mesh a 10 unité plus loin de la position de la camera face a elle sur l'axe localÇà serais possible, je pense que c’est vraiment une fonction utile et manquante a babylon. Merci d'avance Delta Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 3, 2015 Share Posted September 3, 2015 hum something like this:var dir = camera.getTarget().subtract(camera.position);dir.normalize();dir.scaleInPlace(7); sphere.position = camera.position.add(dir); Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 3, 2015 Author Share Posted September 3, 2015 Works perfectly well. So for Forward () function, this could simplify to have to integrate in Babylon? because then I would have never known it done. Thank you very much Delta Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 3, 2015 Author Share Posted September 3, 2015 If I made this:Camera.prototype.forward = function(num) { var dir = this.getTarget().subtract(this.position); dir.normalize(); dir.scaleInPlace(num); return this.position.add(dir);}; I can make a pull request with this for the class Camera.ts? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 3, 2015 Share Posted September 3, 2015 I do not like the name of the function. Seems unclear to me. @English people: do you have a better idea? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 4, 2015 Author Share Posted September 4, 2015 I do not like the name of the function. Seems unclear to me.@English people: do you have a better idea? Yes it's true. May be more appropriate: getFrontPosition() Other ideas? Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted September 6, 2015 Share Posted September 6, 2015 camera.getFrontPosition(distance) looks like quite clear for me jerome and Dad72 2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 6, 2015 Author Share Posted September 6, 2015 Sending pull request: made 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.