Thanks! it works. but the function crashes when I press any button. Please take a look at my functions, I must be doing something wrong. I've tried different things but they cause more or less the same result.

The action:

Code:
action theBall()
{
	while(!player) wait(1);
	
   set(my, SHADOW);
	
	phent_settype(my, PH_RIGID, PH_SPHERE);
	phent_setmass(my, 1, PH_SPHERE);
	phent_setfriction(my,90);
	phent_setelasticity(my,75,100);
	phent_setdamping(my,30,5);
	phent_addvelcentral(my,vector(10,10,0));
	ph_setgravity(vector(0,0,-500));
	
	my.emask |= ENABLE_FRICTION;
	
   	while(1){
   		dist = vec_dist(my.x, player.x);
        if(key_w || key_a || key_s || key_d){
        	move_with_ball();
        	}
   		
   	 
		
		if(key_x){
			kick();
		}
		wait(1);
	}
 }



The function:

Code:
function move_with_ball()
{

while(!my) wait(1);


while(1){
if(dist <= 20){
		proc_mode = PROC_LATE;
      my.x = player.x + 15 * cos(player.pan);
      my.y = player.y + 15 * sin(player.pan);
      my.z = player.z - 15;
      my.pan=player.pan;
      my.roll+=2;
      my.tilt+=2;
}
	if(key_x){
		kick();
	}

}
wait(1);
}



Thanks.


I know I can.