Jump to content

HeightMap and Gravitiy


CodeIain
 Share

Recommended Posts

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

 

 

 

 

Link to comment
Share on other sites

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; // heightfield

That 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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...