Inspired by locoweed's tutorial, i'm trying to make a MP driving game.
But a sort of problem occurs: can't get see my car on the screen. I suppose there's something wrong with "my_car()" function.
here's my piece of code:
Code:
function my_car_client()
{
my_car();
}
function move_car()
{
wait(1);
proc_client(my,my_car_client);
}
//////////////////////////////////////////////
function oldcamera()
{
while(1)
{
dist_planar = cos (tilt_3rd) * dist_total; // vy4eslenie rasstoiania do obiecta po uglu i goriz rasstoianiu
cam_angle = my.pan; //prisvoenie s pogreshnostiu
3rd_person.x = my.x - cos(cam_angle) * dist_planar; // polojenie x ??
3rd_person.y = my.y - sin(cam_angle) * dist_planar; // polojenie y ??
3rd_person.z = my.z + sin(tilt_3rd) * dist_total + 20; // polojenie z ??
3rd_person.pan = cam_angle; // oborot camery
//3rd_person.roll = my.roll * 0.2; // naklon kamery
//3rd_person.tilt = my.tilt * 0.2; //bokovoi naklon kamery ??
wait(1);
}
}
///////////////////////////////////////////
function camspecifics() // once - defines cam options
{
camera.visible = off; // why??
camera.ambient=0;
3rd_person.size_x = screen_size.x; // donno
3rd_person.size_y = screen_size.y; // donno
3rd_person.genius = my; //donno
3rd_person.visible = on; // why???????
}
///////////////////////////////////////////
function carcontrol() // key - dependable control
{
while(1)
{
if(key_cul == on)
{
m1 +=500;
wheel_target = -25;
}
if(key_cur == on)
{
m1 -= 500;
wheel_target = 25;
}
if(key_cul == on && key_cur == on)||(key_cur == off && key_cul == off)
{
m1 = 0;
wheel_target = 0;
}
if(key_cuu == on)
{
m2 += 2000;
}
if(key_cud == on)
{
m2 -= 2000;
}
if(key_cuu == on && key_cud == on)||(key_cuu == off && key_cud == off)
{
m2 = 0;
}
// vec_set(temp, my.x); // makes it so temp is always starts at my.x
//temp.z -= 1000; // set how far to trace
phcon_getposition(joints [1],temp);
vec_set(m1_1,vector((wheel_target)*0.2,100,0));
phcon_getposition(joints [2],temp);
vec_set(m1_2,vector((wheel_target)*0.2,100,0));
phcon_setmotor(joints [1],m1_1,nullvector,nullvector);
phcon_setmotor(joints [2],m1_2,nullvector,nullvector);
phent_addforcelocal ( my, vector (m2,0,0),nullvector );
phent_addtorquelocal ( my, vector(0,0,m1) );
}
wait(1);
}
/////////////////////////////////////////////
function debug()
{
while(1)
{
str_for_num(s3,my.pan);
draw_text(s3,5,40,vector(255,255,255));
str_for_num(s4,my.roll);
draw_text(s4,5,64,vector(255,255,255));
str_for_num(s5,my.tilt);
draw_text(s5,5,88,vector(255,255,255));
str_for_num(s0,my.x);
draw_text(s0,5,112,vector(255,255,255));
str_for_num(s1,my.y);
draw_text(s1,5,136,vector(255,255,255));
str_for_num(s2,my.z);
draw_text(s2,5,160,vector(255,255,255));
wait(1);
}
}
///////////////////////////////////////////
function server_called()
{
// if new player connected, increment people connected// and tell him it's ok to continue
if ((event_type == event_join) && (people_connected < MAX_CONNECTIONS))
{
ifdef server;
people_connected += 1; // another person connected
send_var(people_connected); // send number of people connected
server_says_start = TRUE; // send it's ok to go to newest client
send_var(server_says_start); // send start message
endif; // ifdef server
}
// some one disconnected
if (event_type == event_leave)
{
ifdef server;
people_connected -= 1; // one less person connected to server
send_var(people_connected); // send number of people connected
endif;
}
//on_server = server_called; // on server event, call server_called()
}
///////////////////////////////////////////
function display_info()
{
while(1)
{
str_cpy(str_people_connected, "People Connected: ");
str_for_num(str_temp, people_connected);
str_cat(str_people_connected, str_temp);
wait(1);
}
}
//////////////wheel FUNKtions/////////////////
function frontrightwheel()
{
my.tilt = 90;
//frontright = my;
my.scale_x = 0.25;
my.scale_y = 0.25;
my.scale_z = 0.25;
phent_settype (my,ph_rigid,ph_sphere);
phent_setgroup (my,2);
phent_setelasticity (my,20,10);
phent_setfriction (my,90);
phent_setmass (my,15,ph_sphere);
joints [1] = phcon_add(ph_wheel,player,my);
phent_setdamping(my,50,50);
vec_set(p2,vector(0,0,1));
vec_set(p3,vector(1,0,0));
vec_set(p4,vector(-20,20,0));
vec_set(p6,vector(sc,dc,0));
phcon_setparams1(joints [1],my.x,p2,p3);
phcon_setparams2(joints [1],p4,nullvector,p6);
}
function frontleftwheel()
{
my.tilt = 90;
//frontleft = my;
my.scale_x = 0.25;
my.scale_y = 0.25;
my.scale_z = 0.25;
phent_settype (my,ph_rigid,ph_sphere);
phent_setgroup (my,2);
phent_setelasticity (my,20,10);
phent_setfriction (my,90);
phent_setmass (my,15,ph_sphere);
phent_setdamping(my,50,50);
joints [2] = phcon_add(ph_wheel,player,my);
vec_set(p2,vector(0,0,1));
vec_set(p3,vector(1,0,0));
vec_set(p4,vector(-20,20,0));
vec_set(p6,vector(sc,dc,0));
phcon_setparams1(joints [2],my.x,p2,p3);
phcon_setparams2(joints [2],p4,nullvector,p6);
}
function rearrightwheel()
{
my.tilt = 90;
my.scale_x = 0.25;
my.scale_y = 0.25;
my.scale_z = 0.25;
//rearright = my;
phent_settype (my,ph_rigid,ph_sphere);
phent_setgroup (my,2);
phent_setelasticity (my,20,10);
phent_setfriction (my,90);
phent_setmass (my,15,ph_sphere);
joints [3] = phcon_add(ph_wheel,player,my);
phent_setdamping(my,50,50);
vec_set(p2,vector(0,0,0));
vec_set(p3,vector(1,0,0));
vec_set(p4,vector(0,0,0));
vec_set(p6,vector(sc,dc,0));
phcon_setparams1(joints [3],my.x,p2,p3);
phcon_setparams2(joints [3],p4,nullvector,p6);
}
function rearleftwheel()
{
my.tilt = 90;
my.scale_x = 0.25;
my.scale_y = 0.25;
my.scale_z = 0.25;
//rearleft = my;
phent_settype (my,ph_rigid,ph_sphere);
phent_setgroup (my,2);
phent_setelasticity (my,20,10);
phent_setfriction (my,90);
phent_setmass (my,15,ph_sphere);
joints [4] = phcon_add(ph_wheel,player,my);
phent_setdamping(my,50,50);
vec_set(p2,vector(0,0,0));
vec_set(p3,vector(1,0,0));
vec_set(p4,vector(0,0,0));
vec_set(p6,vector(sc,dc,0));
phcon_setparams1(joints [4],my.x,p2,p3);
phcon_setparams2(joints [4],p4,nullvector,p6);
}
////////////main function////////////////////////////////////////////////////
function main() // predefined "main" function
{
////////////////////////////////////////////////
randomize();
ifdef server;
while(connection== 0) {wait(1);} // wait until level loaded and connection set
endif;
ifdef client;
while(connection== 0) {wait(1);} // wait until level loaded and connection set
endif;
level_load (dorogi_wmb); // load level from previously defined string
sleep(.5);
fps_max = 60; // lock fps at 60 for all players
fps_lock = ON;
mouse_mode = 2; // does not effect forces
if (connection == 2)|| (connection == 3)
{
camspecifics();
oldcamera();
display_info();
debug();
txt_people_connected.visible = ON;
temp.X = 500 + random(100);
temp.Y = 1000 + random(20);
temp.Z = 100;
wait(3);
player = ent_create(car_mdl,temp,my_car);
wait(3);
}
}
///////////////my car FUNKtion////////////////
function my_car() // my car's movement action
{
player.pan = 90;
player.scale_x = 0.6;
player.scale_y = 0.6;
player.scale_z = 0.6;
player=me;
player.overlay = off;
player.flare = off;
player.bright = off;
player.transparent = off;
player.ambient = 50;
player.shadow = off;
player.metal = on;
phent_settype(player,PH_RIGID,PH_box);
phent_setmass(player,1200,PH_box);
phent_setgroup (player, 2); // set the id of the car
phent_setfriction(player,80); //set the friction coefficient
phent_setdamping (player, 50, 50); // set the velocity damping (linear = 20, angular = 30)
phent_setelasticity (player, 10, 5); // set the bounciness factor
ph_setgravity (vector(0, 0, -386));
//ent_create(wheel_mdl, vector(player.x+25,player.y+30,player.z-8),frontrightwheel);
//ent_create(wheel_mdl, vector(player.x-20,player.y+30,player.z-8),frontleftwheel);
//ent_create(wheel_mdl, vector(player.x+25,player.y-30,player.z-8),rearrightwheel);
//ent_create(wheel_mdl, vector(player.x-20,player.y-30,player.z-8),rearleftwheel);
ph_setcorrections(50000,0.1);
i feel so ashamed

(especially with my car physics)