It is not a template script, it is a script partly from Grimber and partly from myself.
EDIT; RE: PHeMox; I have changed the ent_move into c_move and included DISABLE_Z_GLIDE in the move_mode; does not help.
The code for the player;
Code:
//----------
// functions
function jump_handling()
{
if((my.jump_hight>int(my.Jump_Walk_Run) && my.jumping==1)||(my.jumping==2 && my.jump_hight>(frc(my.Jump_Walk_Run)*100)))
{
my.jumping=0;
my.move_vec_z=0;
my.jump_hight=0;
my.jump_percent=0;
}
else
{
if(my.move_vec_z>1*time) //long as our +Z velocity is over 1*time
{
my.move_vec_z-=.5*time; //reduce the +Z velocity
my.jump_hight+=my.move_vec_z; //add the distance the Z velocity covered to update how high we jumped
}
else
{
my.move_vec_z=1*time; //still jumping but at its peak movement up
my.jump_hight+=my.move_vec_z; //same as above
}
}
}
function fall_handling()
{
if(my.fall_distance>64 && sign(my.fall_distance)!=-1 && my.jumping==0)
{
my.falling=1; //I'm falling
if(my.move_vec_z>-15*time) //if not falling at maximum fall rate
{
my.move_vec_z-=.5*time; //then increase my fall rate
}
}
else
{
if(my.fall_distance<32 && my.falling==0 && my.jumping==0) //keep us on the floor normaly
{
my.move_vec_z = -my.fall_distance*time;
}
}
}
function jump_animate()
{
if(my.jump_percent<50)
{
ent_animate(me,"jump",my.jump_percent,anm_add);
my.jump_percent=(my.jump_percent+8*time)%60; //give some added room here so jump_percent can get over 50 for our if check
}
}
function fall_animate()
{
if(my.fall_distance>32)
{
ent_animate(me,"jump",60,anm_add);
}
else
{
if(int(my.land_percent)!=0) //not done with animation yet
{
my.land_percent=(my.land_percent+8*time)%100;
ent_animate(me,"jump",my.land_percent,anm_add); //animate landing
if(my.fall_distance<0) //have we fallen under a surface?
{
my.move_vec_z=-my.fall_distance*time; //if so, move me back up
}
}
else
{
my.falling=0; //we are no longer falling
my.land_percent=60; //reset land_percent fot the next time we might fall
}
}
}
function stand_animate()
{
my.idle_percent = (my.idle_percent +5*time)%100;
ent_animate(me,"stand",my.idle_percent,ANM_CYCLE);
}
function walk_animate()
{
my.walk_percent = (my.walk_percent + sign(my.move_vec_x)*(frc(my.walk_anm_speed)*10)*time)%100;
ent_animate(me,"walk",my.walk_percent,ANM_CYCLE);
}
function run_animate()
{
my.run_percent = (my.run_percent + sign(my.move_vec_x)*(frc(my.run_anm_speed)*10)*time)%100;
ent_animate(me,"run",my.run_percent,ANM_CYCLE);
}
function update_camera()
{
// // camera in 3rd person
// vec_set(temp,my.x);
// vec_sub(temp,camera.x);
// vec_to_angle(camera.pan,temp); //now my looks at you
// camera in 1rst person
vec_set(Camera.x,my.x);
camera.z +=27;
camera.pan=my.pan;
if(mouse_mode==0)
{
my.temptilt+=mouse_force.y*4*time;
}
my.temptilt=clamp(my.temptilt,-75,75);
camera.tilt=0+my.temptilt;
}
function player_events()
{
if(event_type==event_scan && YOU !=player)
{
my.health-=50*(RESULT/200);
}
}
//--------
// actions
//uses: Walk_Anm_Speed,Run_Anm_Speed,Strafe_Anm_Speed,Jump_Walk_Run
//uses: Battery, Armor,Health,Ammo,Battery_max,Armor_max,Health_max,Ammo_max,Keys,falling
//uses: fall_distance,jumping,jump_hight,idle_percent,walk_percent,run_percent
//uses: land_percent,jump_percent,temptilt
//uses: move_vec_x,move_vec_y,move_vec_z
action player_move
{
player=me;
wait(2);
my.falling=0; //not falling
my.jumping=0; //not jumping
my.jump_hight=0; //jump hight=0
my.idle_percent=0;
my.walk_percent=0;
my.run_percent=0;
my.land_percent=60;
my.jump_percent=0;
my.temptilt=0;
camera.genius=player;
shift_sense=int(my.run_anm_speed);
my.enable_scan=ON;
my.event=player_events;
while (my.health>0)
{
vec_set(temp,my.x);
temp.z -= 4000;
trace_mode = ignore_me+ignore_sprites+IGNORE_PASSABLE+USE_BOX;//+ACTIVATE_SONAR
my.fall_distance = trace(my.x,temp);
// check if jumping
if (my.jumping !=0)
{
jump_handling();
}
// check if falling
fall_handling();
// check if player pressed jump X and isn't already juping 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
my.move_vec_z=20*time; //starting jump velocity
}
}
// if not jumping or falling we can move
if(!my.falling && my.jumping==0) //if falling=0 then !falling=-1, or true that I'm not falling
{
my.move_vec_x=(key_force.y)*int(my.walk_anm_speed)*time;
my.move_vec_y=(key_comma-key_period)*int(my.strafe_anm_speed)*time; //strafing
}
// turn players facing
if(mouse_mode==1)
{
player.pan=(player.pan-(key_force.x)*5*time);
}
else
{
player.pan=(player.pan-(key_force.x+mouse_force.x)*5*time)%360;
}
// animations
// jump
if (my.jumping !=0)
{
jump_animate();
}
else //other animations
{
if (my.falling == 1) // animate falling
{
fall_animate();
}
else // animate stand walk and run
{
If (my.move_vec_x == 0 && my.move_vec_y == 0) // stand
{
stand_animate();
}
else // our movement animations will go here
{
if (key_shift) // either shift key is being pressed run aniamtion
{
run_animate();
}
else // shift key is NOT being pressed so we are walking
{
walk_animate();
}
}
}
}
// entity moves
move_mode = IGNORE_YOU+IGNORE_PASSABLE+IGNORE_PUSH+GLIDE+DISABLE_Z_GLIDE; // + ACTIVATE_TRIGGER
// ent_move(my.move_vec_x,NULLVECTOR);
result=c_move(me,my.move_vec_x,NULLVECTOR,move_mode);
update_camera();
wait(1);
}
}
EDIT 2: I just found out that the slowly moving up only occures when you hit a combination of a map entity and a normal block. When you bump into a map entity or to a levelblock, nothing happens, but when you bump into them at the same time the player will rise slowly and ends on the top z value of the map entity, not the levelblock. So my guess is that it has something to do with the difference in world- and local coordinates, but I am not sure of this, but when it is than I can call this a major bug.
Regards,
Frits