Hello guys and girls I have a quick question I am tying to get this model not to float in the air when I press the forward key and use the mouse to pan up, how would I prevent this. Here is the code:
#define _MoveVec 14 /*14 to 16 ARE USED BE THIS SKILL*/
//This function gets the camera to follow the mouse movement and translate
//that into pan/tilt values, accordingly. It does NOT position the camera.
function FirstPersonCamera()
{
while(1)
{
camera.pan -= mouse_force.x * 12 * time_step;
camera.tilt += mouse_force.y * 12 * time_step;
if(camera.tilt > 60)
{
camera.tilt = 60;
}
else
{
if(camera.tilt < -60)
{
camera.tilt= -60;
}
}
wait(1);
}
}
action PlayerMove()
{
//camera made for the player
FirstPersonCamera();
player = my;
//player position on the ground
my.z = - 150;
var ForwardBack = 0;
var LeftRight = 0;
var groundDist = 0;
VECTOR temp;
VECTOR movement;
var anim_percent;
vec_set(movement, vector(0,0,0));
while(!my) wait(1);
while(1)
{
//Forward and back movement
if (key_w == 1) {ForwardBack = 1;}
if (key_s == 1) {ForwardBack = -1;}
if (key_a == 1) {LeftRight = 1;}
if (key_d == 1) {LeftRight = -1;}
if (key_w == 0 && key_s == 0) //No key pressed, clear the mp_move skills
{
ForwardBack = 0;
}
if (key_a == 0 && key_d == 0) //No key pressed, clear the mp_move skills
{
LeftRight = 0;
}
//Now perform local movement prediction
my.skill[_MoveVec] = ForwardBack * 15* time_step;
my.skill[_MoveVec+1] = LeftRight * 7 * time_step;
vec_set(movement, my.skill[_MoveVec]);
//Now move the player
c_move(my,movement,nullvector,IGNORE_PASSABLE | GLIDE | USE_BOX | USE_POLYGON);
vec_set(temp, my.x);
vec_sub(temp, vector(0,0,1000));
groundDist = c_trace(my.x,temp,IGNORE_ME | IGNORE_PASSABLE | USE_BOX | USE_POLYGON);
if ((groundDist > 500 ))
{
my.skill[_MoveVec+2] = -2 * time_step; //Modify Z
}
//Rotation: Player has exact same rotation function as camera. Should use c_rotate! NOTE FOR UPDATE!
my.pan = camera.pan;
my.tilt = camera.tilt;
//Update the camera position
vec_set(camera.x, my.x);
VECTOR Dir;
vec_for_angle(Dir, my.pan);
vec_scale(Dir, -1.7);
vec_add(camera.x, Dir);
//Animate. Not efficient, but hey, good for now...
if ((ForwardBack != 0))
{
anim_percent += 1.3*ForwardBack; // 1.3 = walk cycle percentage per quant
ent_animate(me,"walk",anim_percent,ANM_CYCLE); // play the "walk" animation
}
else // player stands still
{
anim_percent += 1*time_step;
ent_animate(me,"idle",anim_percent,ANM_CYCLE); // play the "stand" animation
}
wait(1);
}
}
Any help is appreciated.
Last edited by Tman; 10/01/09 22:50.