Posted By: Hand_Of_Law
Anet physics (newbie problem) - 08/27/09 11:34
I am making a simple experiment and need some advice on how to make it work.
The basic is the 3D chat example, with an added ball entity.
When the 'b' key is pressed the ball appears for all players, but when a client touches the ball it appears double and constantly jumps between the two positions.
Code:
Any quick help appreciated
The basic is the 3D chat example, with an added ball entity.
When the 'b' key is pressed the ball appears for all players, but when a client touches the ball it appears double and constantly jumps between the two positions.
Code:
Code:
//Lite-C: function receive_ballkick(var sender,STRING* msg) { if (msg = "bounce") { // Create a local speed vector VECTOR vKick; // Use a horizontal and vertical speed to give the ball an upwards kick. vKick.x = 3; vKick.y = 0; vKick.z = 1; // Rotate it in camera direction. // Now apply the speed to the ball, and play a hit sound. phent_addvelcentral(me,vKick); } } function bounce_event() { VECTOR bdirect; if (event_type == EVENT_PUSH) { } if (event_type == EVENT_IMPACT) { enet_clsend_event(19,_str("bounce"),-2); } } function move_ball() { VECTOR ball_dist; //needed for the movement VECTOR save_pos; //stores the entity.pos (needed to find out if the position has changed) VECTOR temp; //a temporary vector var save_pan = 0; //stores the entity.pan (needed to find out if the pan has changed) me.flags |= SHADOW; // Now let's set the ball's physical properties. phent_settype(me,PH_RIGID,PH_SPHERE); phent_setmass(me,1,PH_SPHERE); phent_setfriction(me,90); phent_setelasticity(me,75,100); phent_setdamping(me,30,5); // We add a small speed to give it a little sidewards kick. // phent_addvelcentral(me,vector(10,10,0)); // A ball game would be no fun without gravity. ph_setgravity(vector(0,0,-500)); me.emask |= (ENABLE_FRICTION | ENABLE_PUSH | ENABLE_IMPACT); me.push = 1; me.event = bounce_event; while(enet_ent_globpointer(my) == -1) {wait(1);} //wait until the entity gets a global pointer if(enet_get_connection() !=2) { while(1) { wait(1); //needed for c_updatehull c_updatehull(my,0); //updates the collsision hull enet_send_pos(enet_ent_globpointer(my),-1); wait(1); } } } function ball_startup() { VECTOR creating_pos; //position were the entity will be created while(enet_get_connection() == 0) {wait(1);} //wait until a host is initialized while(1) { if(key_b == ON && enet_get_connection() != 2) { if (ingame == 0) { creating_pos.x = 0;creating_pos.y = 0;creating_pos.z=0; eBall = enet_ent_create(_str("ball.mdl"),creating_pos,_str("move_ball")); ingame = 1; } } if(key_c == ON && enet_get_connection() != 1) { enet_clsend_event(19,_str("shoot"),-2); //sends the shoot message to the server while (key_c == ON) {wait(1);} } wait(1); } }
Any quick help appreciated