CodeIain Posted April 10, 2015 Share Posted April 10, 2015 Hi am new to Babylon.js and am totaly loving it. I have followed this tutorial, to build a FPS, but when I try and change the ground to a height map and apply gravity this drops my framerate to about 2 FPS when I try and move the Camera. It I turn the gravity off the game runs at 60 FPS. Could anyone point me in the right direction for using Gravity with a height map. My code can be found here Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 10, 2015 Share Posted April 10, 2015 Same as previous post: collisions with complex mesh is not a good idea (or you can wait for the webworker version of the collisions which should solve this issue) Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 10, 2015 Share Posted April 10, 2015 You can use an octree for collisions. This should improve performance. http://babylondoc.azurewebsites.net/page.php?p=22561 I can not wait to see this DK for Webworker Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 11, 2015 Share Posted April 11, 2015 Hi Codelain, welcome to the forum! Did you get a good answer? This thread, and your other thread... both talk about heightMap ground. When deltakosh says "complex mesh", he is talking about the heightMap ground. (I re-stated this in case he was unclear) Under a basic camera/ground collisions scene, the camera "collider" is the imaginary sphere that keeps the camera from falling through the ground. When you activate your virtualJoystick to move a box, sphere, camera, etc, you move it on X and Z axis... but the Y axis of the object is still pushed against the ground. Scene.gravity is forcing the object downward... all the time. This causes near-continuous collision activity ground-to-object. Frame rates slow. You can try object.ellipsoidOffset(0, 0.1, 0)) to raise the collider a small amount, but that might cause the object to sink into the ground further. This "continuous rubbing" is a problem, for both standard BJS collisions AND physics engine collisions. Idea: When moving gravity-affected objects across heightMap terrain, turn off collisions on the object that is moving. Or turn off scene gravity. Teach the sphere, box, or camera... how to do "terrain following" instead. I have heard of people using "ray casting" (related to "picking") to measure distance... such as distance from the bottom of a moving object... to the height of the ground underneath. This would be done in the animation loop, and maybe ONLY during a joystick move. Near-continuously, the object would cast a ray beneath itself to check HOW FAR it is above the ground, and it re-adjusts its height to .1 above the ground. Now you can move the object X/Z with the joystick... and the object will always keep itself SOME distance above the terrain... no more, no less. I'm not experienced with measuring distance with rays, but maybe others will comment. I know others have tried this. Dad72 is maybe THE most experienced "move things across heightMaps" guy... in the whole tristate region. He said this, once:var pickInfo = yourGround.pick(yourObject.position.x, yourObject.position.z);pickInfo.pickedPoint.y; // heightfieldThat looks like the beginning of a terrain-following calculator, eh? (thx dad72) Be sure to read http://www.html5gamedevs.com/topic/5385-heightmap-terrain-and-physics/#entry32532 and do forum search for 'heightMap'... because lots of people have talked about these things. Quote Link to comment Share on other sites More sharing options...
CodeIain Posted April 15, 2015 Author Share Posted April 15, 2015 Hi Sorry for the double post. Thanks for all the help I worked out that using the octree that dad72 recommended working for my needs. Regards Wingnut 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.