quote:
Originally posted by DocJoe:
I let fall the following ball on/in a passable block (water). I really get stange behaviour (the ball becomes like a shark, hehehe!) . What do you think about? Is there a way of improvement?


I think i have a code that should do. It works fine for me.

code:
 
var earthgravity[3] = 0,0, -386;
function emit_sphere(); //prototype of the function


sound whamm = <explo.wav>;
sound dump=<dump.wav>;

function shoot_event
{
if (EVENT_TYPE == EVENT_shoot)
{
ENT_playSOUND(MY,whamm,1000);
vec_set(temp,normal);
vec_scale(temp,40000);
phent_addcentralforce ( my, temp );
}

if (EVENT_TYPE == EVENT_friction)
{
ENT_playSOUND(MY,dump,1000);

}

if (EVENT_TYPE == EVENT_Block)
{

if(vec_length(bounce)>100)
{
my.skill41=snd_playing(my.skill40);
if(my.skill41==0)
{my.skill40=ENT_playSOUND(MY,dump,200);}
}

}
// etc. ...
}


function phset() //Normalbahaviour
{
phent_setmass(my, 0.5, PH_Sphere);
phent_setfriction(my, 70);
phent_setelasticity(my, 70,20);
phent_setdamping(my, 20, 20 );

}


function wphset()//Waterbehaviour
{
phent_setmass(my, 0.001, PH_Sphere);
phent_setfriction(my, 70);
phent_setelasticity(my, 70,20);
phent_setdamping(my, 95, 95 );

}



action sphere

{

var speedvec[3];//for waterbehaviour
var onwater=0;
my.metal=on;
my.shadow=on;
my.enable_block=on;
my.ENABLE_shoot = ON;
my.EVENT = shoot_event;



ph_setgravity( earthgravity );
phent_settype(my, PH_RIGID, PH_SPHERE);
phent_setmaxspeed(my,30000, 5000);

phset();
wait(5);

vec_set(speedvec,nullvector);
speedvec.z=1;

temp.x=cos(camera.pan)*cos(camera.tilt)*30000;
temp.y=sin(camera.pan)*cos(camera.tilt)*30000;
temp.z=sin(camera.tilt)*30000;

phent_addforcelocal(my,temp,nullvector);


while(1)
{

if(content(my.x)==2) // Entity on passable Block?
{
if(onwater==0)
{
wphset(); //set Physic-Params for Waterbehaviour
onwater=1;
}
phent_addcentralforce(my,speedvec);
}
else
{
if(onwater)
{
onwater=0;
phset(); //No longer in Water->reset params
}
}
wait(1);
}


}

string mdl_sphere=<sphere3.mdl>;

function emit_sphere()
{
temp.x=camera.x+cos(camera.pan)*cos(camera.tilt)*100;
temp.y=camera.y+sin(camera.pan)*cos(camera.tilt)*100;
temp.z=camera.z+sin(camera.tilt)*100;
temp.z=camera.z+sin(camera.tilt)*100;
ent_create(mdl_sphere,temp,sphere);
}

on_mouse_left=emit_sphere;