Hi, I'm having a little problem with simple multiplayer camera views. I would like to fix the current view on a player (as in first person) so that:
camera.x = player.x;
camera.y = player.y;
camera.z = player.z + 50;
But my problem is if I place the above code in the while loop for my player both the server client and client have the same camera view!
If I place the above code only within an if statement that is run by the client, the server client shows a correct view but the client view does not!
I read in old topics that camera is a global VIEW pointer and unlike the ENTITY* pointer, player, it is the same for all clients in multiplayer. How can I have separate views for each client so that they get their own camera view?
I have already tried creating new views on runtime via
reset(camera,VISIBLE);
VIEW* my_view;
my_view = view_create(1);
wait(1);
set(my_view,VISIBLE);
outside the main player while loop and then updating my_view.x/y/z to the player's x/y/z but the same thing happens.
The below code is the complete action for your reference. It is exactly the same code from workshop25 in Lite-C Tutorial with exception to the addition of the creation of VIEW* my_view and updating the view in the loop:
action player_move() // control the player on its client, move it on the server, animate it on all clients
{
my.event = player_remove;
my.emask |= ENABLE_DISCONNECT;
my.smask |= NOSEND_FRAME; // don't send animation
var walk_percentage = 0;
var skill1_old = 0, skill2_old = 0;
reset(camera,VISIBLE);
VIEW* my_view;
my_view = view_create(1);
wait(1);
set(my_view,VISIBLE);
while (1)
{
if (my.client_id == dplay_id) // player created by this client?
{
if (key_w-key_s != my.skill1) { // forward/backward key state changed?
my.skill1 = key_w-key_s;
send_skill(my.skill1,0); // send the key state in reliable mode
}
if (key_a-key_d != my.skill2) { // rotation key changed?
my.skill2 = key_a-key_d;
send_skill(my.skill2,0); // send rotation state in reliable mode
}
my_view.x = my.x;
my_view.y = my.y;
my_view.z = my.z + 50;
my_view.pan = my.pan;
}
if (connection & CONNECT_SERVER) // running on the server?
{
if (my.skill1 != skill1_old) { // if movement changed
send_skill(my.skill1,SEND_ALL); // send movement to all clients
skill1_old = my.skill1;
}
if (my.skill2 != skill2_old) { // if rotation changed
send_skill(my.skill2,SEND_ALL); // send rotation to all clients
skill2_old = my.skill2;
}
}
my.pan += my.skill2*5*time_step; // rotate the entity using its skill2
var distance = my.skill1*5*time_step;
c_move(me, vector(distance,0,0), NULL, GLIDE | IGNORE_PASSABLE); // move it using its skill1
walk_percentage += distance;
ent_animate(me,"walk",walk_percentage,ANM_CYCLE); // animate the entity
wait (1);
}
}
Thanks in advance!
