Jump to content
  • Advertisement
Sign in to follow this  
Medo Mex

Player Falling on Terrain Heights Instead of Moving

This topic is 2031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When the player move on the terrain heights (mountain), the player fall on the terrain instead of moving normally, which make the player appear like they are able to fly, see the attached picture.


Here is the code that I'm using for moving forward:


D3DXMatrixRotationYawPitchRoll(&matRot, D3DXToRadian(rotationX), D3DXToRadian(rotationY), D3DXToRadian(rotationZ));

D3DXVECTOR3 vecForward;
D3DXMatrixTranslation(&ZUnitVec, 0.0f, 0.0f, 1.0f);  // Matrix holding position of vector pointing to positive Z
D3DXMATRIX m = ZUnitVec * matRot;
vecForward = D3DXVECTOR3(m._41,m._42,m._43); // Get vector from the matrix

newX -= (elapsedTime * speed) * vecForward.x;
if (rotationY != 1.0f)
    newY -= (elapsedTime * speed) * vecForward.y;
newZ -= (elapsedTime * speed) * vecForward.z;

How do I modify the above code to make the player move on the terrain normally, without flying?


I'm using Bullet Physics.

Share this post

Link to post
Share on other sites

Yep, that's typically what it looks like when you just move an object in two dimensions. In your case it appears like the player object moves along the (x,z) plane.


Try incorporating an alternative up vector besides (0,1,0) into your calculations, so the first push isn't straight away from the slope, but rather along the slope, then there will be less "falling", "skipping" or "flying" behavior. :)

Share this post

Link to post
Share on other sites

Tried to change the line:


D3DXMatrixTranslation(&ZUnitVec, 0.0f, 0.0f, 1.0f);



D3DXMatrixTranslation(&ZUnitVec, 0.0f, 1.0f, 1.0f);

Solved the problem, but that doesn't seem to work correctly with other meshes (anything other than characters), should I use a different code for other meshes?

Share this post

Link to post
Share on other sites

By other meshes I assume you mean horses and vehicles, which are longer/wider than they are tall?


Basically you have to work at the four corners of the oriented bounding box and find the up vector based on that. Reimer Grootjans covers the algorithm in one of his XNA programming recipes.




Section 4-17.

Correctly Tilt a Model Corresponding to the

Terrain Underneath

Edited by Steve_Segreto

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!