•      Sign In
• Create Account

## Player Falling on Terrain Heights Instead of Moving

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Medo3337  Members

891
Like
0Likes
Like

Posted 24 March 2013 - 04:53 AM

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:

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

D3DXMATRIX ZUnitVec;
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.

### #2Steve_Segreto  Members

2007
Like
0Likes
Like

Posted 24 March 2013 - 10:43 AM

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.

### #3Medo3337  Members

891
Like
0Likes
Like

Posted 24 March 2013 - 11:12 AM

Tried to change the line:

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

To:

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?

### #4Steve_Segreto  Members

2007
Like
1Likes
Like

Posted 24 March 2013 - 12:46 PM

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.

http://shiba.hpe.sh.cn/jiaoyanzu/WULI/soft/XnaRecipes/XNARecipes.pdf

Section 4-17.

Correctly Tilt a Model Corresponding to the

Terrain Underneath

Edited by Steve_Segreto, 24 March 2013 - 12:51 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.