action player_move
{
player = me;
wait(1);
camera.genius = player;
while (me != NULL)
{
move_vec[0] = (key_force.y)*7 *time; //forward/back
move_vec[1] = (key_a-key_d) *7 *time; //strafe
Vec_set( temp.x, player.x); // copies player x/y/z/ to the temp vector
Temp.z -=4000; // we set the temp vector 4000 quants straight down, below the player entity
trace_mode = ignore_me+ignore_sprites+ACTIVATE_SONAR+IGNORE_MODELS+USE_BOX;
move_vec.z = (-trace(my.x,temp))*2*time;
My.fall_distance = trace(my.x,temp);
}
// check if jumping
if (my.jumping !=0)
{
if ( (my.jump_hight > 32 && my.jumping == 1) || (my.jumping == 2 && my.jump_hight >64) )
{
my.jumping = 0;
move_vec.z = 0;
my.jump_hight = 0;
jump_percent = 0;
}
else
{
if (move_vec.z > 1*time) // long as our +Z velocity is over 1*time
{
move_vec.z -= .5*time; // reduce the +Z velocity
my.jump_hight += move_vec.z; // add the distance the Z velocity covered to update how high we jumped
}
else
{
move_vec.z = 1*time; // still jumping but at its peak movement up
my.jump_hight += move_vec.z; // same as above
}
}
}
else
{
if (move_vec.z > 1*time) // long as our +Z velocity is over 1*time
{
move_vec.z -= .5*time; // reduce the +Z velocity
my.jump_hight += move_vec.z; // add the distance the Z velocity covered to update how high we jumped
}
else
{
move_vec.z = 1*time; // still jumping but at its peak movement up
my.jump_hight += move_vec.z; // same as above
}
}
// check if player pressed jump X and isn't already jumping or falling
if (key_x)
{
if(my.jumping == 0 && my.falling == 0 && my.fall_distance <1)
{
my.jumping = 1 + key_shift; // if holding shift key when hit jump means we were running
move_vec.z = 20*time; // starting jump speed velocity
}
}
// if not jumping or falling we can move
if (!my.falling && my.jumping ==0) // if falling = 0 then !falling is = 1, or true that I'm not falling
{
move_vec.x = (key_force.y)*4 *time; // moved these 2 lines from before my trace
move_vec.y = (key_comma - key_period) *3 *time;
}
If (my.fall_distance >32)
{
my.falling = 1; // now I'm falling
if (move_vec.z > -20*time) // if not falling at maximum fall rate
{
move_vec.z -= .5*time; // then increase my fall rate
}
}
player.pan += (-key_force.x)*4 *time; //look left/right
move_mode = IGNORE_YOU + IGNORE_PASSABLE + IGNORE_PUSH + ACTIVATE_TRIGGER + GLIDE;
ent_move(move_vec,NULLVECTOR);
// animate jump
if (my.jumping !=0)
{
if (jump_percent < 50)
{
ent_animate(me,"jump",jump_percent,ANM_ADD);
jump_percent = (jump_percent +8*time)%60; // give some added room here so the jump_percent can get over 50 for our if check
}
else//other animations
{
if (my.falling == 1)
{
if (my.fall_distance > 32)
{
ent_animate(me,"jump",60,anm_add);
}
else
{
if (int(land_percent) !=0 ) // not done with animation yet
{
land_percent = (land_percent +8*time)%100;
ent_animate(me,"jump",land_percent,ANM_ADD); // animate landing
if (my.fall_distance < 0) // have I fallen under a surface?
{
move_vec.z = -my.fall_distance*time; // if so, move me back up
}
}
else // landing animation done
{
my.falling = 0; // we are no longer falling
land_percent = 60; // reset land_percent for the next time we might fall
}
}
}
else
{
if(move_vec[0]== 0 && move_vec[1]==0)
{
idle_percent = (idle_percent +5*time)%100;
ent_animate(me,"stand",idle_percent,ANM_CYCLE);
}
else
{
//movement animations here
run_percent = (run_percent + sign(move_vec[0])*7*time)%100; // just changed the word walk to run
ent_animate(me,"run",run_percent,ANM_CYCLE);
}
}
}
vec_set(temp,my.x); // copies my loc to temp
vec_sub(temp,camera.x); // subtracts camera loc from temp to calculate a direction vector from camera to my
vec_to_angle(camera.pan,temp); // rotates pan and tilt of the camera to the temp direction vector
//camera updates
/*
Vec_set (Camera.x,player.x);
camera.z += 27;
camera.pan = player.pan;
temptilt += (key_pgup - key_pgdn)*4*time;
If (key_home) { temptilt = 0; }
if (temptilt > 75)
{
temptilt = 75;
}
else
{
if (temptilt < -75)
{
temptilt = -75;
}
}
camera.tilt = 0 + temptilt;
*/
;
wait(1);
}
}
[/sorce]
🔒 Locked
endless loop suggestions?
Advertisement
Original Post
hey, I am trying to add jumping to my game but when i start it it says there is an endless loop in player_move. Does any one have suggestions. and I am sorry this is a lot of code... but if you don't mind, would you look through it and try to help me. thank you. edit: I worked it out. thank you for your help. [Edited by - hungryhobo14 on September 21, 2005 12:54:09 PM]
hi hungryhobo!
there is no way that 'me' changes to 'NULL' within this loop !!
that causes the problem...or can the variable be changed by another thread ??
hope this helps!
there is no way that 'me' changes to 'NULL' within this loop !!
while (me != NULL){ move_vec[0] = (key_force.y)*7 *time; //forward/backmove_vec[1] = (key_a-key_d) *7 *time; //strafeVec_set( temp.x, player.x); // copies player x/y/z/ to the temp vectorTemp.z -=4000; // we set the temp vector 4000 quants straight down, below the player entity trace_mode = ignore_me+ignore_sprites+ACTIVATE_SONAR+IGNORE_MODELS+USE_BOX;move_vec.z = (-trace(my.x,temp))*2*time;My.fall_distance = trace(my.x,temp);}that causes the problem...or can the variable be changed by another thread ??
hope this helps!
Ok let me get this straight: the following loop has me != NULL as its condition but never modifies me? Unless in a very weird way it ends up modifiying me, this explains an infinite loop to me...
Otherwise use debugging -- trace to the point it loops in or where you suspect it. You should be able to find it out.
Illco
PS: on a side note, isn't it frightening how little sense the following line makes to anyone but the programmer?
So I'm adding ignore_me to the ACTIVATE_SONAR flag to compute the trace mode. Uhuh.
while (me != NULL){ move_vec[0] = (key_force.y)*7 *time; //forward/back move_vec[1] = (key_a-key_d) *7 *time; //strafe Vec_set( temp.x, player.x); Temp.z -=4000; trace_mode = ignore_me+ignore_sprites+ACTIVATE_SONAR+IGNORE_MODELS+USE_BOX; move_vec.z = (-trace(my.x,temp))*2*time; My.fall_distance = trace(my.x,temp); }Otherwise use debugging -- trace to the point it loops in or where you suspect it. You should be able to find it out.
Illco
PS: on a side note, isn't it frightening how little sense the following line makes to anyone but the programmer?
trace_mode = ignore_me+ignore_sprites+ACTIVATE_SONAR+IGNORE_MODELS+USE_BOX;So I'm adding ignore_me to the ACTIVATE_SONAR flag to compute the trace mode. Uhuh.
Quote:
Original post by hungryhobo14
...and I am working in gamestudio.
Which means, I suspect, that the language is not actually C but a bastardized version of it, subject to all sorts of conditions that traditional C/C++ programmers here on GameDev (such as myself) don't know about.
Does it even have a debugger? If not, it'd be a bit harder to figure this problem out.
Sorry I can't really help you,
Twilight Dragon
Thanks a lot for the help but I don't think that it is the WHILE me != null line.
that has always worked and thats what i was told to do. Are there any other things you can think of? I dont think Game studio has a debugger.
that has always worked and thats what i was told to do. Are there any other things you can think of? I dont think Game studio has a debugger.
Quote:
Original post by Illco
PS: on a side note, isn't it frightening how little sense the following line makes to anyone but the programmer?trace_mode = ignore_me+ignore_sprites+ACTIVATE_SONAR+IGNORE_MODELS+USE_BOX;
So I'm adding ignore_me to the ACTIVATE_SONAR flag to compute the trace mode. Uhuh.
If they're flags then adding is going to be the same as logically ORing them isn't it?
Anyway, to the OP...just change that "while" to an "if" and see if it fixes your bug. Its easy!
Edit: nevermind, didn't see OP's edit.
Quote:
Original post by bjle Quote:
Original post by Illco
PS: on a side note, isn't it frightening how little sense the following line makes to anyone but the programmer?trace_mode = ignore_me+ignore_sprites+ACTIVATE_SONAR+IGNORE_MODELS+USE_BOX;
So I'm adding ignore_me to the ACTIVATE_SONAR flag to compute the trace mode. Uhuh.
If they're flags then adding is going to be the same as logically ORing them isn't it?
Well, yes, but if you have two flags that have the same value and you + 'em then you end up modifing the wrong bits. With ORing you never activate bits that are nore used by the flags.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement