Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Player forward movement


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.

  • You cannot reply to this topic
5 replies to this topic

#1 Medo3337   Members   -  Reputation: 676

Like
0Likes
Like

Posted 23 March 2013 - 08:46 AM

I'm moving the player FORWARD, but I have a slight problem, 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?

Attached Thumbnails

  • falling.png

Edited by Medo3337, 24 March 2013 - 04:50 AM.


Sponsor:

#2 Jason Z   Crossbones+   -  Reputation: 5164

Like
0Likes
Like

Posted 23 March 2013 - 10:25 AM

Once you have your newX, newY, and newZ values, you have to check them against the height of the terrain and update the newY value accordingly.  Make sure you do the correction immediately, before you generate the new transformation matrices.

 

Note that this will help with the current problem that you have, but the root of the issue is that your forward vector should be modified according to the slope of the terrain.  This will also help you with the relative ground speed seeming different between flat ground and sloped ground.



#3 Medo3337   Members   -  Reputation: 676

Like
0Likes
Like

Posted 23 March 2013 - 12:27 PM

@Jason Z: I think this is not efficient, the heights doesn't necessarily have to be terrain, it could be any mesh.



#4 Jason Z   Crossbones+   -  Reputation: 5164

Like
0Likes
Like

Posted 23 March 2013 - 01:37 PM

@Medo3337: Then how do you propose would be more efficient?  You have to be able to know what elevation your camera should be at, so if it is testing against a mesh or the terrain, or both, then it is going to take some processing time.

 

The only time you wouldn't do this type of testing is if you had a physics API that was managing the height for you, and automatically taking into account the meshes and terrain around you.  I'm not really sure why you would think this is inefficient...



#5 Medo3337   Members   -  Reputation: 676

Like
0Likes
Like

Posted 23 March 2013 - 02:22 PM

@Jason Z: I'm using Bullet Physics.



#6 Jason Z   Crossbones+   -  Reputation: 5164

Like
0Likes
Like

Posted 23 March 2013 - 02:43 PM

@Jason Z: I'm using Bullet Physics.

Oh - well that is a very relevant piece of information!  In that case, you probably need to find an expert in Bullet Physics, and you should probably move this post to an appropriate sub-forum...  I don't think your question is with respect to DirectX - it is more of a physics API question.






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.



PARTNERS