Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (juanex, AndrewAMD), 988 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
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 Offline OP
Expert
Rondidon  Offline 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 frown

Code:
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! laugh

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 Offline
Expert
WretchedSid  Offline
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] #356512
02/02/11 15:30
02/02/11 15:30
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Rondidon Offline OP
Expert
Rondidon  Offline OP
Expert

Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Okay, you`re right. Thanks for the info tongue

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 Offline
User
TheShooter  Offline
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? grin

mfG
The Shooter

Last edited by TheShooter; 02/02/11 15:33.

Staub ist das neue Prime!!

Programming is like sex:
One mistake and you have to support it for the rest of your life.

Aktuelles Projekt: http://thisiswargame.bplaced.net/index.html

A8 Commercial *freu*
Player movement (Framerate + Collision Box) [Re: TheShooter] #356516
02/02/11 15:38
02/02/11 15:38
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Rondidon Offline OP
Expert
Rondidon  Offline OP
Expert

Joined: Aug 2002
Posts: 2,183
Germany, BaW�
I already locked the framerate to
fps_max = 60.

The difference is very noticable nevertheless. You can jump like spiderman on low framerates (5fps) and on high framerates it`s like Jabba the Hut (100fps).

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
M
muffel Offline
Member
muffel  Offline
Member
M

Joined: Oct 2009
Posts: 149
Germany
Code:
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: Rondidon] #356520
02/02/11 16:16
02/02/11 16:16
Joined: Nov 2010
Posts: 96
Vienna
S
Schubido Offline
Junior Member
Schubido  Offline
Junior Member
S

Joined: Nov 2010
Posts: 96
Vienna
Hi, it seems you are mixing up the change of speed and current movement. I think you need two variables for this to be frame rate independed.

jump:
jumpspeed = 5;

movement loop:
player_gravitiy[2] = jumpspeed*time_step; // movement vector for actual frame
jumpspeed -= gravitity*time_step; // change of speed

I am just wondering, why your player jumps higher with low frame rates - reading your code I would have expected a higher jump with high frame rates (=low value for time_frame).

Guess gravitity = 1 and time_frame = 0.5, this would result in a height of
5+4.5+4+3.5 ... + 0.5 = 27.5
with gravitity = 1 and time_frame = 1 (lower frame rate) height would be
5+4+3+2+1 = 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 Offline OP
Expert
Rondidon  Offline 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. laugh

Any ideas for the collison box?

Re: Problems with player movement (Framerate + Collision Box) [Re: Rondidon] #356524
02/02/11 16:42
02/02/11 16:42
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Rondidon Offline OP
Expert
Rondidon  Offline OP
Expert

Joined: Aug 2002
Posts: 2,183
Germany, BaW�
@Schubido: Could you modify Muffel`s code? I don`t really understand how to solve this in the code. Thanks very much.

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 Offline
User
xxxxxxx  Offline
User

Joined: Jan 2011
Posts: 797
Da wo du nicht bist! Muhahaha!
i change the colisions box like this
Code:
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! tongue
Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1