var temp[3];
function move_players() // both entities are controlled by the server
{
var walk_percentage;
var stand_percentage;
while (1)
{
c_move(my, vector(my.skill1, 0, 0), nullvector, GLIDE); // move the entity using its own skill1
my.pan += my.skill2; // and rotate it using its own skill2
if (my.skill1) // the player is moving the entity? (skill1 isn't zero)
{
walk_percentage += 1.5 * my.skill1 * sign(my.skill1); // allow forward / back animations
ent_animate(my, "walk", walk_percentage, ANM_CYCLE); // animate the entity
stand_percentage = 0; // reset stand_percentage
}
else
{
stand_percentage += 1.2 * time_step; // the "stand" animation values don't depend on player's input
ent_animate(my, "stand", stand_percentage, ANM_CYCLE); // animate the entity
walk_percentage = 0; // reset walk_percentage
}
ent_sendnow(my); // send the updated entity position regardless of the "dplay_entrate" value, etc
wait (1);
}
{
camera.pan -= mouse_force.x * 12 * time_step;
camera.tilt += mouse_force.y * 8 * time_step;
camera.tilt = clamp(camera.tilt,-30,100);
temp = fcos(camera.tilt,-camera_distance);
vec_set(camera.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 10 + fsin(camera.tilt,-camera_distance)));
vec_diff(temp[0],camera.x,my.x); //find the vector from the player to the camera
vec_normalize(temp[0],16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(temp[0],camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
trace_mode = ignore_me+ignore_passable+ignore_models;
result = trace(my.x,temp[0]); //trace from the player to 16 quants behind the camera.
IF (result > 0)
{
vec_diff(temp[0],my.x,target[0]); //find the vector from the point the trace hit to the player
vec_normalize(temp[0],16); //get the magnitude of this vector to 16 quants and store in temp
vec_set(camera.x,target.x); //place the camera at the trace hit point
vec_add(camera.x,temp[0]); //move the camera away from the wall by the vector temp, 16 quants towards the player
}
wait(1);
}
}