2 registered members (AndrewAMD, Ayumi),
1,395
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: [Anet] physics movement setup
[Re: darkinferno]
#285892
08/21/09 09:31
08/21/09 09:31
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Gumby22don is right it must be 0x00000008 because 0x00000006 is not a power of two (I make this mistake quite often ^^). Btw. the scancodes I used are NOT the scancodes of w-a-s-d!
Best would be to work with the debugger or print the variable.
Test it this way: - press forward key => see what value skill1 has on the client (1) - press backward key => check the value (2) - press left key => check the value (4) - press right key => ckeck the value (8)
The correct values are in the brackets.
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]
#285938
08/21/09 16:39
08/21/09 16:39
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Ok I think I found the problem:
forward_key = my.skill1&0x00000001; //get bit1
backward_key = (my.skill1&0x00000002)>>1; //bet bit2
left_key = (my.skill1&0x00000004)>>2;
right_key = (my.skill1&0x00000008)>>3;
This should work now.
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]
#287580
09/01/09 13:31
09/01/09 13:31
|
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 it does work, i've been away for a while but in my absence i found several problems with the code setup, this is how i receive the controls on the server:
if(enet_get_connection() == SERVER_MODE || enet_get_connection() == CLIENT_SERVER_MODE)
{
//set up the physic stuff
var forward_key;
var backward_key;
var left_key;
var right_key;
var space_key;
my.can_jump=0;
while(1)
{
forward_key = my.skill1&0x00000001; //get bit1
backward_key = (my.skill1&0x00000002)>>1; //get bit2
left_key = (my.skill1&0x00000004)>>2; //get bit3
right_key = (my.skill1&0x00000008)>>3; //get bit4
space_key = (my.skill1&0x000000016)>>4; //get bit5
with the above code setup, i can only move on the server/client not on the normal clients, in order to move on the regular clients i have to add: " || enet_get_connection() == CLIENT_MODE "
if(enet_get_connection() == SERVER_MODE || enet_get_connection() == CLIENT_SERVER_MODE || enet_get_connection() == CLIENT_MODE )
{
//set up the physic stuff
var forward_key;
var backward_key;
var left_key;
var right_key;
var space_key;
my.can_jump=0;
while(1)
{
forward_key = my.skill1&0x00000001; //get bit1
backward_key = (my.skill1&0x00000002)>>1; //get bit2
left_key = (my.skill1&0x00000004)>>2; //get bit3
right_key = (my.skill1&0x00000008)>>3; //get bit4
space_key = (my.skill1&0x000000016)>>4; //get bit5
this allows movement on the client but it also moves the entity directly, meaning that, even if i remove the "enet_send_pos" the model still moves... i really wanna get this basic setup running
|
|
|
Re: [Anet] physics movement setup
[Re: darkinferno]
#287594
09/01/09 14:36
09/01/09 14:36
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Can you post the whole function and tell me what it exactly should do for you. Then I can tell you where the problem is.
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]
#287605
09/01/09 15:19
09/01/09 15: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)
|
var updateRate;
function control_player()
{
var oldskill1;
var save_pan = 0; //stores the entity.pan (needed to find out if the pan has changed)
if(enet_get_connection() == CLIENT_SERVER_MODE) proc_mode = PROC_LATE;
trigger_ctrl();
while(1)
{
player_camsys(); //this is cam system of the player, found in player_system.c
//store the keys as bits in a skill1
my.skill1 = 0;
my.skill1 |= key_pressed(key_for_str("f")); //forward key in bit0
my.skill1 |= key_pressed(key_for_str("v"))<<1; //backward key in bit1
my.skill1 |= key_pressed(key_for_str("c"))<<2; //left key in bit2
my.skill1 |= key_pressed(key_for_str("b"))<<3; //right key in bit3
my.skill1 |= key_pressed(key_for_str("Space"))<<4; //right key in bit4
enet_send_skills(enet_ent_globpointer(my),6,6,SERVER);
if(my.skill1 != oldskill1 && enet_get_connection() != CLIENT_SERVER_MODE)
{enet_send_skills(enet_ent_globpointer(my),1,1,SERVER); oldskill1=my.skill1;} //oldskill1=my.skill1;
camera.pan -= 2*mouse_force.x; //rotates the entity with the mouse
camera.tilt += 2*mouse_force.y; //rotates the entity with the mouse
my.pan=camera.pan;
my.skill[2] = camera.pan; //damages the player
my.skill[10] = camera.tilt; //damages the player
if(save_pan != my.pan) {enet_send_skills(enet_ent_globpointer(my),2,2,-1); save_pan = my.pan;}
enet_send_skills(enet_ent_globpointer(my),10,10,SERVER);
wait(1);
}
}
function move_player()
{
//[UNUSED]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)
var timePassed = 0;
while(enet_ent_globpointer(my) == -1) {wait(1);} //wait until the entity gets a global pointer
//pl_animate(1); // this contains the blended animation states
key_ctrlr(); //controls key inputs
if(enet_ent_creator(enet_ent_globpointer(my)) == enet_get_clientid())
{
//Every client controls his own player
control_player();
control_anim_st(); // this control local animations
}
else
{
control_other_anim_st();
}
if(enet_get_connection() == SERVER_MODE || enet_get_connection() == CLIENT_SERVER_MODE || enet_get_connection() == CLIENT_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
phent_setdamping(my,100.0, 100.0);//Reibung definieren & drehungsdämpfung nach kollision
// phent_setgroup(player, 2);
var forward_key;
var backward_key;
var left_key;
var right_key;
var space_key;
my.can_jump=0;
while(1)
{
forward_key = my.skill1&0x00000001; //get bit1
backward_key = (my.skill1&0x00000002)>>1; //get bit2
left_key = (my.skill1&0x00000004)>>2; //get bit3
right_key = (my.skill1&0x00000008)>>3; //get bit4
space_key = (my.skill1&0x000000016)>>4; //get bit5
phys_ctrl(forward_key,backward_key,left_key,right_key);
//jump_ctrl(space_key);
if (my.weap_trigger==1)client_shoot();
//sends the position if changed
if(timePassed >= updateRate)
{
vec_set(my.skill[8],my.x);
enet_send_skills(enet_ent_globpointer(my),8,10,-1); //sends the new skill value
}
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);}
//[UNUSED]sends the angles if they changed
//[UNUSED]if(save_pan != my.pan) {enet_send_angle(enet_ent_globpointer(my),-1);save_pan = my.pan;}
timePassed += time_frame;
wait(1);
}
}
else
{
// my.pan=camera.pan;
// my.skill2=my.pan;
// enet_send_skills(enet_ent_globpointer(my),2,2,SERVER);
}
}
basically what i want is for each player to be created as a physics entity on the server[works so far] now i want each client to send the keys pressed to the server, the server then moves that clients' entity and send the positions bac to each client
|
|
|
Re: [Anet] physics movement setup
[Re: darkinferno]
#287710
09/02/09 09:31
09/02/09 09:31
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Don't do to many steps in one. This is the code how I told you this could be done, right? This should be working this way: The clients send the control input for there players to the server/clientserver. The server/clientserver moves the entity using the physic engine and sends the positions and angles every frame to all the other participants.
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)
{
phent_settype(my, PH_RIGID, PH_BOX);//physik entity definieren & kollision = sphere
phent_setmass(my, 75, PH_SPHERE);//masse definieren & rotation = sphere
phent_setdamping(my,100.0, 100.0);//Reibung definieren & drehungsdämpfung nach kollision
// phent_setgroup(player, 2);
while(1)
{
var forward_key = my.skill1&0x00000001; //get bit1
var backward_key = (my.skill1&0x00000002)>>1; //get bit2
var left_key = (my.skill1&0x00000004)>>2; //get bit3
var right_key = (my.skill1&0x00000008)>>3; //get bit4
var space_key = (my.skill1&0x000000016)>>4; //get bit5
phys_ctrl(forward_key,backward_key,left_key,right_key);
//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);
my.skill1 = 0;
my.skill1 |= key_pressed(key_for_str("f")); //forward key in bit0
my.skill1 |= key_pressed(key_for_str("v"))<<1; //backward key in bit1
my.skill1 |= key_pressed(key_for_str("c"))<<2; //left key in bit2
my.skill1 |= key_pressed(key_for_str("b"))<<3; //right key in bit3
my.skill1 |= key_pressed(key_for_str("Space"))<<4; //right key in bit4
if(my.skill1 != oldskill1 && enet_get_connection() != CLIENT_SERVER_MODE) enet_send_skill(enet_ent_globpointer(my),1,1,SERVER);
wait(1);
}
}
I will show you how you correctly make a updaterate and interpolation when the code above is working for you and you understood the code.
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]
#288430
09/06/09 09:45
09/06/09 09:45
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
i take it this problem is a bit hard to manage? No, this is a simple snippet. Just add me to ICQ (see profil for ICQ number) and I will help you there (this will go much faster).
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]
#288482
09/06/09 19:16
09/06/09 19:16
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
The problem is solved now. I posted final snippet with update_rate and interpolation in the Lite-C Contributions forum.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
|