zapat 53 Posted April 23, 2013 (edited) I would like to know which direction a terrain is falling from a given position. I've been experimenting with SurfaceNormal, which returns a vector, I just can't really make it work. I dont need the gradient, only the direction of a slope. (That is the 2D projection of that 3D vector I guess.) I've been trying to place down marker arrows by setVectorDir (surfaceNormal _pos), but I am obviously not understanding something as I don't get good results... If you know a solution I'd be thankful. EDIT: Hell, I needed to ask to find the very easy solution. surfacenormal can be used very easily: I just need to ask its x to x, its y to y. ( I multiplied it by 10 to get bigger numbers) _s = surfaceNormal (getPos player); _p = [((getPos player) select 0) + ((_s select 0) * 10),((getPos player) select 1) + ((_s select 1) * 10), 0]; _dir = ([getPos player,_p] call BIS_fnc_dirTo); Edited April 23, 2013 by zapat Share this post Link to post Share on other sites
MrSherenai 1 Posted April 24, 2013 As the normale of a surface is always perpendicular to the surface itself you want to analyse the tilt of the normal vector. You just want it in 2D as you want to know the falling direction and not the angle. So all you need is this formula: _dir = (_s select 0) atan2 (_s select 1); Share this post Link to post Share on other sites
killzone_kid 1326 Posted April 24, 2013 if you use vectorUp with surfaceNormal it will give you x and y Share this post Link to post Share on other sites
zapat 53 Posted April 24, 2013 Thanks guys! MrSherenai: you mean: _pos = getPos player ((_s select 0) - (_pos select 0)) atan2 ((_s select 1) - (_pos select 1)); don't you? Share this post Link to post Share on other sites
MrSherenai 1 Posted April 24, 2013 (edited) Nope, what you try to do there is create a vector that spans from _s to _pos and get that vectors direction. View this image as reference what the normale of a surface is: Click me! Imagine the vector returned by surfaceNormale as one of those little black arrows sticking out of a surface. You want to know the direction of the surace this little black arrow belongs to.The returned vector is normalized and just giving the 3D direction the black arrow is pointing to. If you want for example some kind of object to be 10 meters away from that surface and standing in right angle relative to the surface you can just multiply the vector returned by 10, add the position you used as input argument for surfaceNormale and use the result as position for the object. In your case all you want is to get the slopes direction what can be easily calculated out of the normale vector. Imagine a light source thats is somewhere straight over the origin of one of the black arrow. The arrow will cast a shadow similar to the one in this image (imagine the yellow arrow being the black surface normale, the shadow will be casted from the origin to the point where the blue and green dotted lines meet) Click me!. And the direction of that shadow, in the last image it is actually the bottom black dottted line, is what you want to calculate. Thus there is no need for you to struggle with positions and needless calculations, all you need is to get the angle alpha by calculating "atan(y/x) = alpha" . BIS added a function for this calculation that returns its output in degrees and thats the function atan2 I mentioned above. Be aware of that atan2 returns values ranging from -180° to 180° so if you want just positives you may have to add 360° when the angle is negative. I hope I didnt confuse you^^ Edited April 24, 2013 by MrSherenai Share this post Link to post Share on other sites
zapat 53 Posted April 24, 2013 No, you didn't! Thank you for your detailed answer, I appreciate it. :) And, actually, I understand it now. I knew there must be a simplier way, I am just not too good at maths. Share this post Link to post Share on other sites