Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help with basic platform physics...

Started by somebodykulj Apr 11, 2008 at 8:49 AM 2 replies 1k views
Original Post
somebodykulj
somebodykulj
I have made a simple platform game that when press space jumps when press ctrl accelerates and with acceleration the jump is higher and when i jump so high with acceleration and try to control where the player would land i get tooo much control becouse when i press right or left the player moves around the x axis just as fast as on the gorund and it looks bad, the bottom line is that when i start the jump the player will jump allong the x axis and acceleration but when a key is pressed during the jump i want to be able to controlle the player BUT not so much so that it looks like he can fly. here is my code...

if(lockjump==true )//SIMULACIJA GRAVITACIJE U VAZDUHU
{
   if(xtime%200==0)
   {
      velx*=0.9;
   }
}
else  
velx*=0.000099;



if(keystates[SDLK_RIGHT])
{
   velx = VELMOVING;
   faceright = true;	
   W_RIGHT=true;
}
else W_RIGHT=false;
	
if(keystates[SDLK_LEFT])
{
   velx =-VELMOVING;	
   faceright = false;	
   W_LEFT=true;	
}
else W_LEFT=false;

if(keystates[SDLK_SPACE] && !lockjump)
{
  ON_GROUND==false;	
  vely = -VELJUMP;		
  lockjump = true;
  jumping = true;       	
}

if(keystates[SDLK_LCTRL] && (W_LEFT==true || W_RIGHT==true))
{
   if (lockjump==false) 
   {
      if (VELMOVING<15)        
      {
         VELMOVING+=0.5;
      }
                   
      if (VELJUMP<25 )                       
      {
         if(xtime%3==0)
         VELJUMP+=1;
      }
   }                           	
}
else
{
if (VELMOVING > 4)
VELMOVING-=1;
       
if (VELJUMP>15)                       
VELJUMP-=1;
} 
xtime is my way of cehcking the time it ads up 1 on every main loop... i need to be able to control the player when making an accelerated jump BUT not too much...
Thaumaturge
Thaumaturge
I think that you should be able to achieve this by checking in your key -left and -right code whether the character is off of the ground. If they are off of the ground, multiply the value that you use to modify the character's x-velocity by some small number. (Less than 1.0, but greater than 0.0.)

For example, multiplying it by 0.5 should cause the player to move at half speed in the air.
MWAHAHAHAHAHAHA!!! My Twitter Account: @EbornIan
somebodykulj
somebodykulj
I have tried that, but no it doesent do what i want, i want the player to keep moving in high speed BUT when i am controlling him int the air then da playa may not move so much.
Thaumaturge
Thaumaturge
Fair enough...

In that case, I note that in your key-press code you set the player's x-velocity. Have you tried altering it instead, and altering it by a lower amount when the player is in the air?

If you do do this, then I would suggest finding the time between such updates and taking that into account.

For example, you might have something like this (in pseudocode):

if KEY_RIGHT pressed {  if(not_in_the_air) velx += VELMOVING*time_since_last_update;  else velx += 0.5*VELMOVING*time_since_last_update; }//Similarly for left key-presses


Note that you will probably also want to include a damping force to slow the player down (to a stop, eventually), which might take a little tuning.

Otherwise, you might get away with checking the player's x-velocity, and, if it is positive, only changing it if the current value is less than the air x-velocity, and if it is negative only changing it if the current value is greater (i.e. less negative) than -(air x-velocity).
MWAHAHAHAHAHAHA!!! My Twitter Account: @EbornIan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.