action controller(){
//parameters to change
int moveSpeed = 30;//inch in one ticks...thats how fast world recordlers run
float stopFactor = 0.7;//the velocity of the player gets multiplied with that every frame
int maxStepHeight = 16;//name says all. 16 inches should be even too high
int groundDist = 1;//don't make it hard for the collision system
float gravity = 2;//in a vacuum it would be ca. 24 inch/tick^2 (9.81 m/s^2)
float heighCorrectionFactor = 0.9;//for climbing stairs and slopes
int jumpForce = 10;//how good can you jump?
move_min_z = 0.707;//stairclimping by c_move not over 45° of the elipsiod
//used by player function
VECTOR moveDir;
VECTOR movement;
float fallDist;
int onGround = 0;
VECTOR vel;
vec_zero(moveDir);
vec_zero(movement);
vec_zero(vel);
player=me;
wait(1);
c_setminmax(me);
while(1){
moveDir.x = (key_w-key_s); //get direction
moveDir.y = (key_a-key_d);
my.pan -= 2*mouse_force.x;
camera.tilt = clamp(camera.tilt + 2*mouse_force.y,-90,90);
fallDist = c_trace(player.x, vector(my.x, my.y, my.z - 500), IGNORE_ME | IGNORE_YOU | IGNORE_SPRITES | IGNORE_MODELS | USE_BOX);
//check for ground contact
if(fallDist <= groundDist)
onGround = 1;
else
onGround = 0;
//help me with stairs
if(moveDir.x || moveDir.y){//moving?
//trace down where you're moving to
VECTOR stairTracePos;
vec_set(stairTracePos, moveDir);
vec_normalize(stairTracePos, my.max_x);
vec_rotate(stairTracePos, my.pan);
vec_add(stairTracePos, vector(my.x, my.y, my.z+my.min_z));
result = c_trace(vector(stairTracePos.x, stairTracePos.y, stairTracePos.z+maxStepHeight), stairTracePos, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|IGNORE_MODELS);
if(trace_hit){
my.z += (maxStepHeight-result+groundDist)*heighCorrectionFactor*time_step;
onGround = 1;
}
}
//gravitation
if(!onGround){
vel.z -= gravity*time_step;
}
else
vel.z = 0;
//jumping
if(onGround && key_space){
vel.z = jumpForce;
}
//xy-movement
if(moveDir.x)
vel.x = 15*moveDir.x;
else
vel.x *= 1.0-(1.0-stopFactor)*time_step;//anti propotional relation
if(moveDir.y)
vel.y = 15*moveDir.y;
else
vel.y *= 1.0-(1.0-stopFactor)*time_step;//anti propotional relation
movement.x = vel.x*time_step;
movement.y = vel.y*time_step;
c_move(me, nullvector, vector(0,0, vel.z), GLIDE|IGNORE_PASSABLE);//if we jump, we might crash against the ceiling
c_move(me, movement, nullvector, GLIDE|IGNORE_PASSABLE);//now move on xy
vec_set(camera.x, my.x);
camera.z += 32.5;
camera.pan = my.pan;
wait(1);
}
}