|
2 registered members (juanex, AndrewAMD),
988
guests, and 8
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Problems with player movement (Framerate + Collision Box)
#356505
02/02/11 14:59
02/02/11 14:59
|
Joined: Aug 2002
Posts: 2,183 Germany, BaW�
Rondidon
OP
Expert
|
OP
Expert
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
|
Hello, I want to code a framerate independant player movement code for a first person shooter, but I don`t know what I`m doing wrong. The x-y movement works perfectly, but the jump height isn`t framerate independant. On low framerate you can jump much higher than on high framerate. Do you know why? Second problem: The collison box. I want it to be thicker, but it doesn`t work. Can you help me? Here`s the code snippet (copy it to SED for better overview). I hope you´ll find the errors. I don`t have any clue what´s wrong 
action player()
{
player_collision_box();
move_player(); //Bewegung und Maussteuerung
}
function player_collision_box() //This function doesn`t have ANY effect. The collison box stays the same size. But why?
{
set(my,FAT|NARROW);
my.max_x=35; //make bigger if player sould be thicker
my.min_x=-35;
my.max_y=35;
my.min_y=-35;
my.max_z=100;
my.min_z=-100;
move_min_z = 0.4;
wait(1);
}
function player_jump()
{
player_gravitiy[2]=5; //Problem 1: Framerate dependant, but why? And no, time_step is no option, because the jump hight has to be fix.
}
function move_player()
{
//[..]
while(1)
{
// [...]
c_move (my,player_movevector ,nullvector,IGNORE_PASSABLE|IGNORE_SPRITES|GLIDE|USE_BOX);
player_height = c_trace(vector(my.x,my.y,my.z),vector(my.x,my.y,my.z-2000), IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES | USE_BOX); //Get the player hight via trace
if(player_height<37)
{
player_gravitiy[2]=10*time_frame;
}
else
{
if(player_height>43)
{
player_gravitiy[2]-=gravitation*time_frame; //Problem 1: Framerate dependant, but why? Also look at player_jump()
}
else
{
if(move_jump == 0)
{
player_gravitiy[2] = 0;
}
}
}
if((move_jump==1)&&(result<45)){player_jump();}
c_move (my,nullvector ,player_gravitiy,IGNORE_PASSABLE|IGNORE_SPRITES|GLIDE|USE_BOX); //Problem 2: Collison box is mini, but why? Also see function collison_box()
wait(1);
}
}
Thank you very much for helping! 
|
|
|
Re: Problems with player movement (Framerate + Collision Box)
[Re: Rondidon]
#356510
02/02/11 15:25
02/02/11 15:25
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Dude, fancy colors, fancy typo and hey guys only works if you have boobs.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Problems with player movement (Framerate + Collision Box)
[Re: WretchedSid]
#356513
02/02/11 15:32
02/02/11 15:32
|
Joined: Jul 2010
Posts: 974 United Arab Emirates, Dubai
TheShooter
User
|
User
Joined: Jul 2010
Posts: 974
United Arab Emirates, Dubai
|
I have the same problem. Somewhere in the manual is explained, how to solve this. Sorry, don't know where. Its there, were the "fps_max" is explained. Sorry for my bad english, isn't it bad?  mfG The Shooter
Last edited by TheShooter; 02/02/11 15:33.
|
|
|
Re: Problems with player movement (Framerate + Collision Box)
[Re: Rondidon]
#356518
02/02/11 16:02
02/02/11 16:02
|
Joined: Oct 2009
Posts: 149 Germany
muffel
Member
|
Member
Joined: Oct 2009
Posts: 149
Germany
|
var player_z_speed = 0;
action player()
{
player_collision_box();
move_player(); //Bewegung und Maussteuerung
}
function player_collision_box() //This function doesn`t have ANY effect. The collison box stays the same size. But why?
{
set(my,FAT|NARROW);
my.max_x=35; //make bigger if player sould be thicker
my.min_x=-35;
my.max_y=35;
my.min_y=-35;
my.max_z=100;
my.min_z=-100;
move_min_z = 0.4;
wait(1);
}
function player_jump()
{
player_z_speed=5; //Problem 1: Framerate dependant, but why? And no, time_step is no option, because the jump hight has to be fix.
}
function move_player()
{
//[..]
while(1)
{
// [...]
c_move (my,player_movevector ,nullvector,IGNORE_PASSABLE|IGNORE_SPRITES|GLIDE|USE_BOX);
player_height = c_trace(vector(my.x,my.y,my.z),vector(my.x,my.y,my.z-2000), IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES | USE_BOX); //Get the player hight via trace
if(player_height<37)
{
player_z_speed=10*time_frame;
}
else
{
if(player_height>43)
{
player_z_speed-=gravitation*time_frame; //Problem 1: Framerate dependant, but why? Also look at player_jump()
}
else
{
if(move_jump == 0)
{
player_z_speed = 0;
}
}
}
if((move_jump==1)&&(result<45)){player_jump();}
player_movedist[2] = player_z_speed;
c_move (my,nullvector ,player_movedist,IGNORE_PASSABLE|IGNORE_SPRITES|GLIDE|USE_BOX); //Problem 2: Collison box is mini, but why? Also see function collison_box()
wait(1);
}
}
I have tried to make your code framerate independent. I have the feeling that not everyone understand the relationship of acceleration( gravity ), movement , distance and c_move. c_move requires the distance which the ent should walk in the frame. So you have to multiply the speed with the time to get the distance. The collision box thing: you have to wait a frame before you change the bounding box, not after changing muffel
Last edited by muffel; 02/02/11 16:15.
|
|
|
Re: Problems with player movement (Framerate + Collision Box)
[Re: muffel]
#356521
02/02/11 16:24
02/02/11 16:24
|
Joined: Aug 2002
Posts: 2,183 Germany, BaW�
Rondidon
OP
Expert
|
OP
Expert
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
|
Thanks very much, Muffel. But it didn`t solve the problem. It`s now reversed: Player jumps high with high framerate and low with low framerate. @ Schubido: I`m looking into this. Thanks.  Any ideas for the collison box?
|
|
|
Re: Problems with player movement (Framerate + Collision Box)
[Re: Rondidon]
#356525
02/02/11 16:47
02/02/11 16:47
|
Joined: Jan 2011
Posts: 797 Da wo du nicht bist! Muhahaha!
xxxxxxx
User
|
User
Joined: Jan 2011
Posts: 797
Da wo du nicht bist! Muhahaha!
|
i change the colisions box like this
function player_collision_box()
{
wait(1);
c_setminmax(my);
my.min_x = -35;
my.min_y = -35;
my.min_z = -100;
my.max_x = 35;
my.max_y = 35;
my.max_z = 15;
}
mfg xxxxxxx
Last edited by xxxxxxx; 02/02/11 16:48.
Es ist immer wieder erstaunlich, dass Leute die riesen Scripte schreiben die einfachsten sachen nicht können zb. mich mit SIEBEN x zu schreiben!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|