Convergence Posted September 14, 2015 Share Posted September 14, 2015 Hello,Is there a way to retrieve/calculate the angle (slant) of a mesh created by CreateGroundFromHeightMap() at a certain x, z coordinate? (or any mesh for that matter). The pickResult of ground.intersects(ray) does not seem to give this information, however there are a mysterious 'bu' and 'bv' property on the object, I haven't yet figured out what those mean. It would be nice to know, for example, to rotate a mesh to be exactly perpendicular to the Ground it is resting on. I could of course dive into the vertices array and slog through a lof of cos() sin() and toa()s to get it, but perhaps babylon already has a neat function for that I'm overlooking? Slightly related question regarding gravity and collisions:Even if the ground is only very slightly slanted, a gravity-affected-object will already start to slide down, which can get irksome after a while. For reasonable slants this is good and realistic of course, but it would be nice if a little bit of grip could be had. Quote Link to comment Share on other sites More sharing options...
adam Posted September 14, 2015 Share Posted September 14, 2015 I think you should be able to do something like this: var pickNormal = pickResult.getNormal();var angle = Math.acos(BABYLON.Vector3.Dot(pickNormal, new BABYLON.Vector3(0, 1, 0))); Quote Link to comment Share on other sites More sharing options...
Convergence Posted September 15, 2015 Author Share Posted September 15, 2015 Thanks, worked like a charm Quote Link to comment Share on other sites More sharing options...
Convergence Posted November 18, 2015 Author Share Posted November 18, 2015 I have a follow-up question; the above method only returns one float value which indicates that the face is angled, but not towards which axis, which makes it insufficient for the following scenario: Say you are moving a car across a heightmap, the car should of course follow the curve of the landscape regardless of its own orientation. Is there an easy way calculate its rotation so it looks like all 4 wheels still have contact with the ground? Preferably without the use of ray.intersects() since it is rather slow and I was already able to eliminate its use from my project. The 'hard' way I can think of is to dive in the ground._positions array, retrieve the applicable vertices and do some heavy trigonometry on them; but perhaps there is an easier way? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 18, 2015 Share Posted November 18, 2015 Hi guys! ConV... I think you should un-answer this thread, if possible. This is great subject... and hasn't been talked-about in this forum... enough (imho). I assume you are NOT using a physics engine, so the slant of a "tile" is important for "coasting" the vehicle, too. The slant under each tire can be summed, and then averaged, to see if the car would roll if in neutral gear. But maybe the normal of the car body... compared to "up"... would return something usable, too. I think this is a hot topic, and we could use all the car-on-heightMap fun that we can find. Personally, I like jumping vehicles, but that might require a physics engine... so I can get maximum tumbling carnage when I crash-land. Quote Link to comment Share on other sites More sharing options...
Convergence Posted November 19, 2015 Author Share Posted November 19, 2015 Hi guys! ConV... I think you should un-answer this thread, if possible. This is great subject... and hasn't been talked-about in this forum... enough (imho). I assume you are NOT using a physics engine, so the slant of a "tile" is important for "coasting" the vehicle, too. The slant under each tire can be summed, and then averaged, to see if the car would roll if in neutral gear. But maybe the normal of the car body... compared to "up"... would return something usable, too. I think this is a hot topic, and we could use all the car-on-heightMap fun that we can find. Personally, I like jumping vehicles, but that might require a physics engine... so I can get maximum tumbling carnage when I crash-land. Thanks for the reply Actually I had already marked the thread as unresolved before replying , but now it seems its 'Answered' again. Weird, I don't know what happened there. 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.