math & physics
anddos at September 14th, 2008 05:19 — #1
i am stuck with thinking how to make the .x player animation move up a terrain that is not flat but has bumps and hills , would it be something todo with the vertexbuffer and the player translation current postion?
reedbeta at September 14th, 2008 14:22 — #2
If your terrain is stored as a heightfield, then what you need to do is:
- use the player's x and y coordinates to find the grid square of terrain they are currently in
- look up the heights of the four corners of that grid square in the heightfield
- use bilinear interpolation to calculate the height of the terrain at the player's exact x and y coordinates
- translate the player so that the feet are at that height (z).
Later on you'll probably want to implement some physics so that the player can't climb up slopes that are too steep. But this should get you started.