[/code]
////////////////////////////////////////////////////////////////////
string work01_wmb = <yourlevel.wmb>;
entity* don_rob_ent;
entity* up_rob_ent;
function moving_robo_func();
function robo_player();
////////////////////////////////////////////////////////////////////
function main()
{
fps_max = 50;
level_load (work01_wmb);
wait(5);
ent_create ("dn_robo.mdl", vector(0,0,0), robo_player);
}
function robo_player()
{
var down_point_tmp;
don_rob_ent = me;
my.passable = on; /// Avoid interference when moving!!
//////////////////////////////
// create up part
vec_for_vertex(down_point_tmp,me,29);
up_rob_ent = ent_create("up_robo.mdl",down_point_tmp,NULL);
//////////////////////////////
moving_robo_func();
//////////////////////////////
// place camera
camera.tilt = -15; // look down at the player, play with this value
while(1)
{
wait(time_step);
camera.x = me.x - 350 * cos(me.pan); // 250 = distance between the player and the camera, play with this value
camera.y = me.y - 350 * sin(me.pan); // use the same value here
camera.z = me.z + 150; // place the camera above the player, play with this value
camera.pan = me.pan; // the camera and the player have the same pan angle
}
}
function moving_robo_func()
{
var anim_percentage; // animation percentage
var movement_speed; // player's movement speed
var distance_to_ground; // the distance between player's origin and the ground
var down_point_tmp;
while (1)
{
my.pan += 6 * (key_a - key_d) * time; // rotate the player using the "A" and "D" keys
vec_set (temp, my.x); // copy player's position to temp
temp.z -= 5000; // set temp.z 5000 quants below player's origin
distance_to_ground = c_trace (my.x, temp.x, ignore_me | use_box | ignore_you);
movement_speed.x = 5 * (key_w - key_s) * time_step; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 100); // 17 = experimental value
movement_speed.z = max (-35 * time, movement_speed.z); // 35 = falling speed
// move one entity
c_move (don_rob_ent, movement_speed, nullvector, glide); // move the player
// you need to get the position of this vertex every time
vec_for_vertex(down_point_tmp,don_rob_ent,29);
// you need to set the position of this entity every time
// reposition 'p_rob_ent' using the above location
vec_set (up_rob_ent.x, down_point_tmp.x);
if (key_w && key_s) // the player is moving?
{
ent_animate(don_rob_ent, "walk", anim_percentage, anm_cycle); // play the "walk" animation
}
else // the player is not moving?
{
ent_animate(don_rob_ent, "stand", anim_percentage, anm_cycle); // play the "stand" animation
}
anim_percentage += 5 * time; // 5 = animation speed
wait (1);
}
}
[code]