0 registered members (),
1,173
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Disabling a Physics entity
#74708
05/19/06 13:18
05/19/06 13:18
|
Joined: Aug 2003
Posts: 275 Germany
kopitzki
OP
Member
|
OP
Member
Joined: Aug 2003
Posts: 275
Germany
|
How can I stop a physics entity from its jiggling movement when it is supposed to have come to rest, meaning, after a box or cylinder has bounced a couple of times and (is supposed to) stand(s) absolutely still on the ground? Among other things I've unsuccessfully tried things like:
vec_for_vertex(temp,my,2);//include rotation phent_getvelocity(my, mySpeed, temp); temp=vec_length(myspeed);
if(temp<50){phent_setmass(my,0,PH_POLY);} else {phent_setmass(my,10,PH_POLY);}
I've also tried phent_enable and phent_set_type but couldn't find out how to disable the physics entity after all the bouncing and enabling it again when being hit by another physics entity.
|
|
|
Re: Disabling a Physics entity
[Re: kopitzki]
#74709
05/19/06 14:38
05/19/06 14:38
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
Expert
|
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
*gets out kopitzki's manual* Wow, this thing is awful dusty. *flips through to the physics section* There we go, this is what we need. phent_enable (ENTITY* entity, var enable); This function temporarily enables/ disables an entity for physics. If more than one entity is to be changed, it's more efficient to use ph_selectgroup instead. Parameters: entity the entity to be affected enable a value of 1 enables the entity, 0 disables the entity
Returns: 1 if successful, 0 otherwise. Speed: Medium Edition: C P Example: // disable physics entity so we can manually alter its position phent_enable( me, 0 ); vec_set(my.x, newPosition ); vec_set(my.pan, newOrientation ); // re-enable entity, this will inform the physics system that position/orientation has changed. phent_enable( me, 1 ); /// so to disable the entity we put in phent_enable( me, 0 );//we have disabled the physic entity
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: Disabling a Physics entity
[Re: kopitzki]
#74711
05/19/06 19:58
05/19/06 19:58
|
Joined: Aug 2003
Posts: 275 Germany
kopitzki
OP
Member
|
OP
Member
Joined: Aug 2003
Posts: 275
Germany
|
The current stage of things is: The physics entity comes to an absolute rest, due to "phent_enable". But it cannot be initiated when being hit. Code:
var stosskraft=900000; var weapons_type; var cigweight=5; var colaweight=10;
Define mySpeed, my.skill2; Define myoldpos, my.skill5;// not vacant: skill1-16 + to: flag1 Define bounce_on,skill8; Define bounce_handle,skill9; Define bouncesounddelay,skill10; Define dampfaktor,skill11; Define dampmax,skill12; Define soundtype, skill13;
string cigboxstr=<cig_box.mdl>; string canstr=<can.mdl>;
var colfric=35; var colelastmin=100;
var group_id=1;
sound funnyprall1=<blechplump.wav>; sound funnyprall2=<blechhell1.wav>; sound funnyprall3=<dumpf3.wav>; sound funnyprall4=<kartonhell1.wav>;
var test16=50;
function ph_bounce_event { if (EVENT_TYPE == EVENT_block){my.bounce_on=1;}
if (EVENT_TYPE==EVENT_friction) {my.bounce_on=2;my.flag1=off;// enabling physics again // if(you==camdummie or other){phent_addcentralforce(you.speed) } }
FUNCTION play_abprall() { phent_getvelocity(my, mySpeed, nullvector); temp=vec_length(mySpeed);
if(my.bouncesounddelay==1){return;} if(temp<50){if(my.bounce_on==1){my.flag1=on;}return;}
//if(my.bouncesounddelay==1||temp<50){return;}
my.bouncesounddelay=1;
temp=vec_dist(my.x,camera.x);
if(my.bounce_on==1) {if(my.soundtype==1){my.bounce_handle=ent_playsound(my,funnyprall3,max(1000-temp/3,0));} if(my.soundtype==2){my.bounce_handle=ent_playsound(my,funnyprall1,max(1000-temp/3,0));} } if(my.bounce_on==2) {if(my.soundtype==1){my.bounce_handle=ent_playsound(my,funnyprall4,max(1000-temp/3,0));} if(my.soundtype==2){my.bounce_handle=ent_playsound(my,funnyprall2,max(1000-temp/3,0));} } sleep(0.2); my.bouncesounddelay=0; }
var physics_gravity[3];
FUNCTION handle_weapon_physics()
{ group_id+=1;
if(weapons_type==1) {my.soundtype=1; phent_settype(my,PH_RIGID, PH_BOX);phent_setgroup( my, group_id); phent_setmass(my,colaweight/2,PH_box); phent_setfriction(my,colfric);phent_setelasticity(my,40,colelastmin*2); my.dampfaktor=45; my.dampmax=60; } if(weapons_type==2) {my.soundtype=2; phent_settype(my,PH_RIGID, PH_POLY);phent_setgroup( my, group_id); phent_setmass(my,colaweight,PH_POLY); phent_setfriction(my,colfric);phent_setelasticity(my,50,colelastmin); my.dampfaktor=3; my.dampmax=50; }
phent_setdamping(my,my.dampfaktor,75);
physics_gravity.z=-600;//0
ph_setgravity (physics_gravity); ph_setcorrections(50000,0.05);//60000,0.01
phent_enable(my,0);
var t; my.pan=camera.pan+90+t%360;
while(key_ctrl==0)
///////// HIER ENT_MOVE benutzen, um eindringen in wand zu verhindern
{temp.x = screen_size.x/2; temp.y = screen_size.y/2; temp.z = 130; vec_for_screen(temp,CAMERA); vec_set(my.x,temp); my.pan=camera.pan+90+t%360; wait(1); t+=10*time; } phent_enable(my,1);
phent_setmaxspeed( my, 5000, 1000);
my.enable_friction=on; my.enable_block=on;
//my.enable_touch=on;
my.event=ph_bounce_event;
physics_gravity.z=-600;
ph_setgravity (physics_gravity); vec_set(temp,nullvector);
if(weapons_type==1){temp.x=stosskraft/2;} if(weapons_type==2){temp.x=stosskraft;} vec_rotate(temp,camera.pan);
phent_addcentralforce( my, temp );
temp=random(800); phent_addtorquelocal(my, vector(400-temp,400-temp,400-temp));
while(1) { if(my.flag1==off) { phent_enable( my, 1);
vec_for_vertex(temp,my,2);//rotation mit eingbezogen
phent_getvelocity(my, mySpeed, temp);
temp=vec_length(myspeed);
if(temp>1000){phent_setdamping(my, my.dampmax, 75);}
else {phent_setdamping(my, my.dampfaktor, 25);}
// //if(temp<test16){phent_setfriction(my,100);}// auf impact warten //else{phent_setfriction(my,colfric);} //
if(my.bounce_on>0) { play_abprall(); }
my.bounce_on=0; } else{phent_enable( my, 0);}
wait(1);
}
}
FUNCTION CREATE_WEAPON()
{ temp.x = screen_size.x/2; temp.y = screen_size.y/2; temp.z = 100; vec_for_screen(temp,CAMERA);
if(key_1==1){weapons_type=1;ent_create(cigboxstr,temp,handle_weapon_physics);} if(key_2==1){weapons_type=2;ent_create(canstr,temp,handle_weapon_physics);} }
/////////////////////// on_1=CREATE_WEAPON; on_2=CREATE_WEAPON;
|
|
|
Re: Disabling a Physics entity
[Re: kopitzki]
#74714
05/21/06 20:16
05/21/06 20:16
|
Joined: Aug 2003
Posts: 275 Germany
kopitzki
OP
Member
|
OP
Member
Joined: Aug 2003
Posts: 275
Germany
|
So I'm asking for any further advice. I've changed the loop to the following, which seems to work better, but still there might be some trap. Code:
//Define temp_velocity, skill99;
while(1) {
vec_for_vertex(temp,my,2);//rotation mit eingbezogen
phent_getvelocity(my, mySpeed, temp);
my.temp_velocity=abs(vec_length(myspeed));
if(my.temp_velocity>1000){phent_setdamping(my, my.dampmax, 75);}
else {phent_setdamping(my, my.dampfaktor, 25);}
// if(my.bounce_on==1) {if(my.temp_velocity<60)//&&abs(ang(my.tilt))<5||temp<80&&abs(ang(my.roll))<5) { sleep(1);// um nicht in der Luft hängenzubleiben if(my.temp_velocity<60)// still nearly still? { phent_enable( my, 0); while(my.bounce_on==1){wait(1);}// bounce_on=2 only with further impact phent_enable( my, 1); } } }
if(my.bounce_on>0) { play_abprall(); }
wait(1); } }
|
|
|
Re: Disabling a Physics entity
[Re: kopitzki]
#74715
05/23/06 21:18
05/23/06 21:18
|
Joined: Aug 2003
Posts: 275 Germany
kopitzki
OP
Member
|
OP
Member
Joined: Aug 2003
Posts: 275
Germany
|
Current state:
The loop looks like this (collision with blocks seem to work reliably, collision with models definitely doesn't):
while(1) { vec_set(my.skill24,my.x);// for safety
vec_for_vertex(temp,my,3);//rotation mit eingbezogen
phent_getvelocity(my, mySpeed, temp);
my.temp_velocity=abs(vec_length(myspeed));
if(my.temp_velocity>2000){phent_setdamping(my, my.dampmax, 99);}
else {phent_setdamping(my, my.dampfaktor, 85);}// ACHTUNG RECHNUNG STIMMT NICHT!!! //temp=my.temp_velocity/300; //temp=clamp(temp,1,100); //phent_setdamping(my,temp,min(100,temp*20));
// if(my.bounce_on>0) {play_abprall();}
if(my.bounce_on==1) {if(my.temp_velocity<30)//&&abs(ang(my.tilt))<5||temp<80&&abs(ang(my.roll))<5) { sleep(1);// um nicht in der Luft hängenzubleiben if(my.temp_velocity<30)// still nearly still? { phent_enable( my, 0); while(my.bounce_on==1){wait(1);}// bounce_on=2 only with further impact phent_enable( my, 1); } } }
//reset my.bounce_on=0;
// safety check phent_enable(my,0); vec_set(temp,my.x); trace_mode=IGNORE_ME + IGNORE_PASSABLE +use_box; temp=trace(my.x,my.skill24); if(temp<0){vec_set(my.x,my.skill24);} phent_enable(my,1);
wait(1); } }
|
|
|
|