Posted By: 82RJZAE
C_Trace to Ground - 07/22/10 20:37
Hi, I am coding a basic movement script and am having some difficulties with the c_trace function.
It is not returning the value that I thought it should. For example, when I place the player on a block in the level, it returns a value of about 40. This only occurs when the level is first started. The movement code seems to function fine after the first "drop" into the level.
I am using the following line to trace the distance to the ground:
After that, I use the following code to simulate the acceleration due to gravity:
In the above image, the player flies into the sky because c_trace returns a negative value (distance_to_ground = -40). If I place the player 1 quant above the ground in WED, he will fall down at a high move_to_vector.z value (= -52).
Any suggestions that might fix this?
It is not returning the value that I thought it should. For example, when I place the player on a block in the level, it returns a value of about 40. This only occurs when the level is first started. The movement code seems to function fine after the first "drop" into the level.
I am using the following line to trace the distance to the ground:
Code:
distance_to_ground = c_trace(my.x, vector(my.x,my.y,my.z-500), IGNORE_ME | IGNORE_PASSENTS | IGNORE_PASSABLE | IGNORE_SPRITES | USE_BOX);
After that, I use the following code to simulate the acceleration due to gravity:
Code:
if(distance_to_ground >= 0) { accelerate(move_to_vector.z, (-3 * time_step), 0); if(move_to_vector.z < (distance_to_ground * -1)) { move_to_vector.z = distance_to_ground * -1 * time_step; } } else { move_to_vector.z = -1 * distance_to_ground; } ... c_move(me, move_to_vector, nullvector, GLIDE | IGNORE_SPRITES | IGNORE_PASSABLE);
In the above image, the player flies into the sky because c_trace returns a negative value (distance_to_ground = -40). If I place the player 1 quant above the ground in WED, he will fall down at a high move_to_vector.z value (= -52).
Any suggestions that might fix this?