This assumes you are using an actual terrain and are not using an object as a terrain. In this example the ID of the terrain is "1".
#include "DarkGDK.h"
float moveSpeed = 1.0f; // Initiated the variable
float walkSpeed = 1.0f; // Default walk speed
float runSpeed = 1.8f; // Default run speed
float hasteSpeed = 0.0f; // Increases movement speed
float snareSpeed = 0.0f; // Decreases movement speed
void WASDControl() {
// Calculates move speed
if (dbShiftKey() == 1) { moveSpeed = runSpeed + hasteSpeed - snareSpeed; } else { moveSpeed = walkSpeed + hasteSpeed - snareSpeed; }
// W to move forward
if (dbKeyState(17)) { dbMoveCamera(moveSpeed); }
// S to move back
if (dbKeyState(31)) { dbMoveCamera(-moveSpeed); }
// A to turn left
if (dbKeyState(30)){ dbTurnCameraLeft(1.5f * moveSpeed); }
// D to turn right
if (dbKeyState(32)){ dbTurnCameraRight(1.5f * moveSpeed); }
// Q to straffe left
if (dbKeyState(16)) { dbTurnCameraLeft(90); dbMoveCamera(moveSpeed); dbTurnCameraRight(90); }
// E to straffe right
if (dbKeyState(18)) { dbTurnCameraRight(90); dbMoveCamera(moveSpeed); dbTurnCameraLeft(90); }
// Final update on camera position
float fHeight = dbGetTerrainGroundHeight(1, dbCameraPositionX(), dbCameraPositionZ());
dbPositionCamera(dbCameraPositionX(), fHeight + 10.0f, dbCameraPositionZ());
dbSync();
}
------------------------------------
Currently 1500+ lines of code into an "over-the-shoulder" action RPG with combat based on rag-doll physics.