Trying out a script that are supposed to make the player stay on the ground. But when I run it the player are up in the air, a coulpe of centimeters abow the floor. Why does it do that?
What is wrong with my gravity script.
Can anyone of you tell me that? In WED the player stands on the ground, but when I run the script the players are in the air......

GRAVITY code:
Code:
function gravity_player()
{
//////////////////gravity/////////////////////
// determine the ground distance by a downwards trace
//my.min_z *= 0.5;
var speed_down = 0;   // downward speed by gravity
   var anim_percent = 0; // animation percentage
   VECTOR vFeet;
   vec_for_min(vFeet,my); // vFeet.z = distance from player origin to lowest vertex
      
      var dist_down; 
//      if (c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX) > 0)
      if (c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE) > 0)
        dist_down = my.z + vFeet.z - target.z; // get distance between player's feet and the ground
      else
         dist_down = 0;

// apply gravity when the player is in the air
      if (dist_down > 0)  // above floor, fall down with increasing speed
         dist_down = clamp(dist_down,0,accelerate(speed_down,5,0.1));
      else                // on or below floor, set downward speed to zero
         speed_down = 0;

/////////////////////////////////////////////	
}


My Player code:
Code:
action trude_player()

{


      var mov_speed = 10; // movement speed
      var walk_prosent;//walk
      var stand_prosent;//stand

		var spacebar_clear = 1;//jump
		var z_adjust = 0;//jump

      VECTOR temp;
      VECTOR move_to_vector;//jump

		var jump_percentage; // animation percentage for jumping
      var distance_to_ground; // the distance between player's origin and the ground
      var jump_height;
      var reached_height;


///////////////
       player = my; // I'm the player	
			c_setminmax(my);
		//	my.z=1000;
		
       while (1)

       {

               ///////***STAND ******////////////
			//If the player arent moved with these keys, it is standing ... play stand animation
			     if(!key_w && !key_s && !key_cuu && !key_cud) 

             {

                       ent_animate(my, "stand", stand_prosent, ANM_CYCLE); // then play its "stand" animation

                       stand_prosent += 5 * time_step; // 5 = animation speed
                       gravity_player();

               }         
					////////////end stand//////////////////////////////////////////////

				 ////////////////Keys used to move player and play animation///////////////////  
				  
				 //Use key w to walk forward           
				if(key_w)
				{
					 ent_animate(my, "walk", walk_prosent, ANM_CYCLE); // then play its "walk" animation
				
				                       walk_prosent += 6 * time_step; // 6 = animation speed
				                       gravity_player();
				} 
				//Use key s to walk backwards
				if(key_s) 
				{
					 ent_animate(my, "walk", walk_prosent, ANM_CYCLE); // then play its "walk" animation
				
				                       walk_prosent += 6 * time_step; // 6 = animation speed
				                       gravity_player();
				}           
				 //Use key z turn left              
				if(key_d)
				{
					my.pan += 5  * time_step;
					gravity_player();
				}
				//Use key x turn right
				if(key_a)
				{
					my.pan -= 5  * time_step;
					gravity_player();
				}
				
				//use CursorUp to walk forward
				if(key_cuu)
				{
					ent_animate(my, "walk", walk_prosent, ANM_CYCLE); // then play its "walk" animation
				
				                       walk_prosent += 6 * time_step; // 6 = animation speed
				                       gravity_player();
				}
				//use CursorDown to walk backward
				if(key_cud)
				{
					ent_animate(my, "walk", walk_prosent, ANM_CYCLE); // then play its "walk" animation
				
				                       walk_prosent += 6 * time_step; // 6 = animation speed
				                       gravity_player();
				}
				
				//use CursorRight turn right
				if(key_cur)
				{
					my.pan -= 5  * time_step;
					gravity_player();
				}
				
				//use CursorLeft turn left
				if(key_cul)
				{
					my.pan += 5  * time_step;
					gravity_player();
				}
				
				 if(key_n)//start to scan...
				 {
				 	c_scan(my.x, my.pan, vector(360, 180, 200), IGNORE_ME); 
				}
				//use the mouse turn bouth ways
				player.pan -= 5 * mouse_force.x * time_step; 
				
				/////////////////end move keys////////////////////////////////////////


				
				////////////////////JUMP/////////////////////////////////



       VECTOR movement_speed[3]; // player's movement speed

       var anim_percentage; // animation percentage


              vec_set (temp.x, my.x); // copy player's position to temp

               temp.z -= 10000; // set temp.z 10000 quants below player's origin

               distance_to_ground = c_trace (my.x, temp.x, IGNORE_ME | USE_BOX);


               movement_speed.y = 0; // don't move sideways

               if (key_space && !reached_height)

               {

                       jump_height = minv(100, jump_height + 5 * time_step); // 40 sets the height, 5 sets the ascending speed

                       if (jump_height == 100) // reached the maximum height? Then start descending!

                       {

                               reached_height = 1;

                               jump_height = maxv(0, jump_height - 5 * time_step); // 5 sets the falling speed

                       }

               }

               else // space isn't pressed anymore?

               {

                       jump_height = maxv(0, jump_height - 3 * time_step); // use a smaller falling speed (3) for smaller jumps

                       if (!jump_height && !key_space) // the player has touched the ground?

                       {

                               reached_height = 0; // then allow it to jump again

                       }

               }

               movement_speed.z = -(distance_to_ground - 17) + jump_height; // 17 = experimental value

            movement_speed.z = maxv(-35 * time_step, movement_speed.z); // 35 = falling speed

               c_move (my, movement_speed.x, nullvector, GLIDE); // move the player

            if (!jump_height) // the player isn't jumping?

            {

//                   

                       anim_percentage += 5 * time_step; // 5 = animation speed

                       jump_percentage = 0; // always start jumping with the first frame

               }

            else // the player is jumping

            {

                    jump_percentage += 5 * time_step; // 5 = jump animation speed

                       ent_animate(my, "jump", jump_percentage, ANM_CYCLE); // play the "jump" animation

               }

 


					/////////////////////////SPEED////////////////////////////



					temp.x = mov_speed * (key_w - key_s + key_cuu - key_cud) * time_step;


               temp.y = mov_speed * (key_a - key_d) * 0.6 * time_step;
               temp.y = mov_speed * (key_cul-key_cur) * 0.6 * time_step;

               temp.z = 0;
               
               ////////////////////////end speed/////////////////////////

					//bind it al togehter so the player can use the movement in x direction//
               c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);
//                  c_move (my, nullvector, vector(0,0,-1000), IGNORE_PASSABLE | GLIDE);//forandret
                
               
              

               wait (1);

       }

}



A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile