Ahiru Posted September 9, 2015 Share Posted September 9, 2015 Maybe I am just a bit slow understanding, but how can I actually bring a mesh to face the camera? (And further more: Only do that turning around its local "Z"-Axe) Here my trials so far: http://playground.babylonjs.com/#12U7QB#2 Even tried to find out the angle between the actual rotation and the camera, but the actual rotation does not really look right? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 9, 2015 Share Posted September 9, 2015 how can I actually bring a mesh to face the camera? I added a feature in Babylon 2.2 that is available since yesterday: getFrontPosition (distance) to place an object in front of the camera and whatever the rotation and position of the camera. exemple:sphere.position = camera.getFrontPosition(12); //Sphere has 12 unit front the camera.This what you were asking? JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 9, 2015 Author Share Posted September 9, 2015 No - nice function, but probably not what I need at the moment. You see the cylinder lying on the box, right? And I want it to turn its face always to the camera. (But without standing up - it still has to lie flat like it does now - only this movement like shown at the moment allowed) Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 9, 2015 Share Posted September 9, 2015 Can be this:mesh.billboardMode = BABYLON.Mesh.BILLBOARDMODE_ALL;This allows to always orient an object in front of the camera. Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 9, 2015 Author Share Posted September 9, 2015 Unfortunately not: http://playground.babylonjs.com/#12U7QB#3 First of all it shows the wrong site (should be on of the caps) - but mainly it "sinks" into its parent - not really an option Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 9, 2015 Author Share Posted September 9, 2015 It can't look directly at you, because it has only 1 degree of freedom, because it has still to stay on the parent element. http://playground.babylonjs.com/#12U7QB#4 It should try to point as you on it's possible axe as close as possible, so it can "shoot" onto you immediately when the box is in the right position. Quote Link to comment Share on other sites More sharing options...
jerome Posted September 9, 2015 Share Posted September 9, 2015 If you want to rotate a mesh into a known target system (ex : cube top sides and camera axis) so it always face the cam, you may use Vector3.RotationFromAxis() to get the needed rotation angles. doc : http://doc.babylonjs.com/overviews/How_Rotations_and_Translations_Work ("generating a rotation from a target system" part) ex : http://www.babylonjs-playground.com/#VYM1E#5 Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 9, 2015 Author Share Posted September 9, 2015 Well - it can't completely face you, because it's fixed on the "Ship" - maybe it's clearer now like this? http://playground.babylonjs.com/#12U7QB#5 So it can't completely face you (only when the box is aligned correctly), but it can at least turn in your direction on the axis it CAN move. I tried to find out the angle, so I can put it into the quaternion rotation, but I am still not sure how to find this angle. If the cannon would move like you suggested it will break the ship Quote Link to comment Share on other sites More sharing options...
iiceman Posted September 9, 2015 Share Posted September 9, 2015 maybe that helps somehow: http://www.babylonjs-playground.com/#Z3UOX#10 It's rotating the cone to face a certain point before moving there. It only rotates one axis (I tried with more then one but didn't really get it right yet). So that might not be exactly what you need, but could be a start, right? Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 9, 2015 Author Share Posted September 9, 2015 Yes, like this, but that was easy to solve, since click-point, ship and face-to point are all on the same plane. But could not work it out yet to make it work when they are not ... Quote Link to comment Share on other sites More sharing options...
iiceman Posted September 9, 2015 Share Posted September 9, 2015 Hmm, I see... well, then I don't know either Just an idea: maybe you can make them use the same (imaginary) plane for the calculation and then rotate according to that? Trying to illustrate the idea: http://playground.babylonjs.com/#12U7QB#8 By the way: how do I get the coordinates of a mesh in world space?? I somehow couldn't figure it out... might be too late... or just my lack of knowledge... but please tell me Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 10, 2015 Author Share Posted September 10, 2015 plane.position = cylinder.getAbsolutePosition(); (Don't get confused by the console.log show 0,0,0 - if you expand it the real numbers are shown - no idea why that is) But I am struggling with getting the "absolute" rotation of the cylinder. After I rotate it with the .rotate() function - which is done with quaternions - the rotation is always (0,0,0). So now I try to find out how to rotate with quaternions manually. Because how much I have to turn depends not only on the cylinders position, but also on the rotation, right? Quote Link to comment Share on other sites More sharing options...
Temechon Posted September 10, 2015 Share Posted September 10, 2015 Hello, Maybe this will help you (extracted quickly from one of my project) : http://www.babylonjs-playground.com/#HDEBW iiceman and Ahiru 2 Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 10, 2015 Author Share Posted September 10, 2015 Perfect! Thank's a lot Temechon! Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 10, 2015 Author Share Posted September 10, 2015 Only - how do I handle if the box's parent change? When the ground turns round the box faces the wrong direction: http://playground.babylonjs.com/#HDEBW#1 Quote Link to comment Share on other sites More sharing options...
Temechon Posted September 10, 2015 Share Posted September 10, 2015 That's a god question actually I have no idea ! Quote Link to comment Share on other sites More sharing options...
Ahiru Posted September 10, 2015 Author Share Posted September 10, 2015 Do you have good links to learn quaternions? I have the feeling they will accompany me for quite a while now valepu 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.