Hi there, I'm trying to make a decent jump function, and it does run when I'm pressing spacebar (like intended), but my entity flies extremely fast (compareable with Superman I even think ^^) when jumping. I really have no idea what it is wrong the function, if someone knows please say so grin.

Here's the script (only the relevant parts of the script, with red the really relevant parts):



///////////////////////////////
#include <acknex.h>
#include <default.c>

#define STATE skill1
#define ANIMATION skill2
#define CREATOR skill3

///////////////////////////////

...
var jumpheight = 0;
...


// state 5:
jumping ////////////////////////////////////////////

function jump()
{
jumpheight = 1;
my.ANIMATION += 8*time_step;
ent_animate(me,"jump",my.ANIMATION,0);
while (1)
{
jumpheight += 8*time_step;
c_move(me, vector(0,0,jumpheight), NULL, GLIDE);
if (my.ANIMATION > 50) { break;}
wait(1);
}

while (my.ANIMATION > 50)
{
jumpheight -= 8*time_step;
c_move(me, vector(0,0,jumpheight), NULL, GLIDE);
if (jumpheight <= 0)
{
break;
jumpheight = 0;
my.ANIMATION = 0;
my.STATE = 1;
}
wait(1);
}
}

////////////////////////////////////////////////////////////////


function camera_follow(ENTITY* ent)
{
vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
vec_set(camera.pan,vector(ent.pan,-10,0)); // look in player direction, slighty down
while(1)
{
camera.x=mywizard.x-(100)*cos(mywizard.tilt)*cos(mywizard.pan);
camera.y=mywizard.y-(100)*cos(mywizard.tilt)*sin(mywizard.pan);
camera.z=mywizard.z-(50)*sin(mywizard.tilt) + 50;

mywizard.pan = camera.pan;
mywizard.tilt = camera.tilt;
wait(1);
}
}

///////////////////////////////////////////////////////////////////////////

action wizard_walk()
{
mywizard = my;
camera_follow(me);

my.event = wizard_hit;
my.emask |= ENABLE_IMPACT;

VECTOR vFeet;
vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex

// set FLAG2 to make the wizard detectable by c_scan,
// and store the wizard pointer in its own CREATOR skill
// in case the wizard is detected directly
set(my,FLAG2);
my.CREATOR = me;

my.STATE = 1;
while (1)
{
// state 1: walking ////////////////////////////////////////////
if (my.STATE == 1)
{
// rotate the entity with camera rotation


// move the entity forward/backward with the arrow keys + strafe
var distance = (key_w-key_s)*9*time_step;
var distancestrafe = (key_a-key_d)*6*time_step;
c_move(me, vector(distance,distancestrafe,0), NULL, GLIDE);

// animate the entity
my.ANIMATION += (1.2*distance) + (1.2*distancestrafe);
ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);

// adjust entity to the ground height, using a downwards trace
c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
my.z = hit.z - vFeet.z; // always place player's feet on the ground

if (key_space) // spacebar pressed -> jump like a maniac!
{
jump();
my.ANIMATION = 0;
my.STATE = 5;
}