2 registered members (AndrewAMD, juanex),
1,247
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: [Anet] physics movement setup
[Re: darkinferno]
#285687
08/19/09 17:15
08/19/09 17:15
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Can you post your code? (the entity function)
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: [Anet] physics movement setup
[Re: Dark_samurai]
#285703
08/19/09 18:32
08/19/09 18:32
|
Joined: May 2009
Posts: 1,816 at my pc (duh)
darkinferno
OP
Serious User
|
OP
Serious User
Joined: May 2009
Posts: 1,816
at my pc (duh)
|
function move_player()
{
var save_pan = 0; //stores the entity.pan (needed to find out if the pan has changed)
VECTOR save_pos; //stores the entity.pos (needed to find out if the position has changed)
while(enet_ent_globpointer(my) == -1) {wait(1);} //wait until the entity gets a global pointer
if(enet_ent_creator(enet_ent_globpointer(my)) == enet_get_clientid())
{ //Every client controls his own player
while(1)
{
vec_set(camera.x,my.x);
//store the keys as bits in a skill1
// if(my.skill1 != oldskill1) enet_send_skill(enet_ent_globpointer(my),1,1,SERVER);
wait(1);
}
}
if(enet_get_connection() == SERVER_MODE || enet_get_connection() == CLIENT_SERVER_MODE)
{
//set up the physic stuff
phent_settype(my, PH_RIGID, PH_BOX);//physik entity definieren & kollision = sphere
phent_setmass(my, 75, PH_SPHERE);//masse definieren & rotation = sphere
while(1)
{
//use skill1 for the controls of the entity
//sends the position if changed
if(save_pos.x != my.x || save_pos.y != my.y || save_pos.z != my.z) {enet_send_pos(enet_ent_globpointer(my),-1);vec_set(save_pos,my.x);}
//sends the angles if they changed
if(save_pan != my.pan) {enet_send_angle(enet_ent_globpointer(my),-1);save_pan = my.pan;}
wait(1);
}
}
}
thats it so far
|
|
|
Re: [Anet] physics movement setup
[Re: darkinferno]
#285717
08/19/09 19:10
08/19/09 19:10
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Yeah so what's the problem? Now you have to save every key that is used for the controls as a seperate bit in skill1.
And on the server you evaluate the input and do the movement.
Then the snippet is ready.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: [Anet] physics movement setup
[Re: Dark_samurai]
#285721
08/19/09 19:19
08/19/09 19:19
|
Joined: May 2009
Posts: 1,816 at my pc (duh)
darkinferno
OP
Serious User
|
OP
Serious User
Joined: May 2009
Posts: 1,816
at my pc (duh)
|
yes, am not worried about that, what am saying is, with the above code, when i run as server/client, the client that comes with that option isnt receiving any position updates... so when i start a game with server/client:
the character floats there, when i join as another client, i fall to the floor, as i should, all clients see the server/client floating in the air, position isnt being updated, dont know if i'm being clear
|
|
|
Re: [Anet] physics movement setup
[Re: darkinferno]
#285726
08/19/09 19:32
08/19/09 19:32
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Oh you meand that. Yes currently the code is designed that only normal clients can control players. The problem is the if construction. When the client server runs this function and it created the entity the execution of the function get's stuck in the first while loop. This could should also make it able for the client server to control players:
function move_player()
{
var save_pan = 0; //stores the entity.pan (needed to find out if the pan has changed)
VECTOR save_pos; //stores the entity.pos (needed to find out if the position has changed)
while(enet_ent_globpointer(my) == -1) {wait(1);} //wait until the entity gets a global pointer
if(enet_ent_creator(enet_ent_globpointer(my)) == enet_get_clientid())
{ //Every client controls his own player
control_player();
}
if(enet_get_connection() == SERVER_MODE || enet_get_connection() == CLIENT_SERVER_MODE)
{
//set up the physic stuff
phent_settype(my, PH_RIGID, PH_BOX);//physik entity definieren & kollision = sphere
phent_setmass(my, 75, PH_SPHERE);//masse definieren & rotation = sphere
while(1)
{
//use skill1 for the controls of the entity
//sends the position if changed
if(save_pos.x != my.x || save_pos.y != my.y || save_pos.z != my.z) {enet_send_pos(enet_ent_globpointer(my),-1);vec_set(save_pos,my.x);}
//sends the angles if they changed
if(save_pan != my.pan) {enet_send_angle(enet_ent_globpointer(my),-1);save_pan = my.pan;}
wait(1);
}
}
}
function control_player()
{
if(enet_get_connection() == CLIENT_SERVER_MODE) proc_mode = PROC_LATE;
while(1)
{
vec_set(camera.x,my.x);
//store the keys as bits in a skill1
// if(my.skill1 != oldskill1 && enet_get_connection() != CLIENT_SERVER_MODE) enet_send_skill(enet_ent_globpointer(my),1,1,SERVER);
wait(1);
}
}
Please notice the change in the if(my.skill1 != oldskill ... line. If you are controling your player as client server there is no need to send the skill. Also the PROC_LATE is important, otherwise the movement will lag a bit (see manual for PROC_LATE).
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: [Anet] physics movement setup
[Re: darkinferno]
#285798
08/20/09 08:46
08/20/09 08:46
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
I meant it this way: Every key can be pressed or not pressed => 1 or 0 A skill consists of 4 Byte => 32 bit Now you say, bit 1 is the status of the move forward key. If bit1 is 1 this key is pressed, if it is 0 it isn't. This is how you store the keys:
my.skill1 = 0;
my.skill1 |= key_pressed(20); //forward key in bit1
my.skill1 |= key_pressed(21)<<1; //backward key in bit2
my.skill1 |= key_pressed(22)<<2; //left key in bit3
my.skill1 |= key_pressed(23)<<3; //right key in bit4
//and so on
On the server you can get them this way:
forward_key = my.skill1&0x00000001; //get bit1
backward_key = my.skill1&0x00000002; //bet bit2
left_key = my.skill1&0x00000004;
right_key = my.skill1&0x00000006;
//and so on
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
|