Thread: Gravity
View Single Post
  #4  
Old 08-17-2006, 10:45 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
Here's what I have now. The bouncing bug is gone, but the player still goes into the ground on occasion, and sometimes, I fall through moving NPCs.
It works as well as other gravity systems I've seen, so I guess it could be a free script, only I want to improve it. I also plan to change the rate of acceleration for falling, to make it reach the max speed slower, so you can notice the acceleration.
PHP Code:
// NPC made by Excalibur
//GS2 Grav
//#CLIENTSIDE
function onCreated()
{
  
client.no_wep=1;
  
player.dir=3;
  
this.direction=player.dir;
  
this.speed=.05;
  
onTimeout();
}
function 
onTimeout()
{
  
freezeplayer(.05);
  
//set the jump
  
if(keydown(0) && this.jump==&& onwall(player.x+1player.y+3.55))
  {
    
this.speed=.05;
    
this.jump=1;
    
this.count=17;
  }
  
//force fall
  
if(keydown(2))
  {
    if(!
onwall(player.x+1player.y+3.55) && !onwall(player.x+1player.y+this.speed))
    {
      
playery+=(this.speed-.05);
    }
  }
  if(
keydown(1))
  {
    if(
onwall(player.x+1player.y+3.55))
    {
       
setani("walk",NULL);
    }
    if(!
onwall(player.x-.5,player.y) && !onwall(player.x-.5,player.y+3))
    {
      
player.x-=.5;
    }
    
player.dir=1;
  }
  if(
keydown(3))
  {
    if(
onwall(player.x+1player.y+3.55))
    {
       
setani("walk",NULL);
    }
    if(!
onwall(player.x+2.5,player.y) && !onwall(player.x+2.5,player.y+3))
    {
      
player.x+=.5;
    }
    
player.dir=3;
  }
  else if(!
keydown(1) && !keydown(3))
  {
    
setani("idle",NULL);
  }
  
//move
  
if(player.dir==|| player.dir==2)
  {
    
player.dir=this.direction;
  }
  
this.direction=player.dir;
  if(
this.jump==1)
  {
    if(!
onwall(playerx+1,playery-.5) && this.count>0)
    {
       
player.y-=.5;
    }
    else if(
onwall(playerx+1,playery-.5))
    {
      
this.count=0;
    }
    
this.count--;
    if(
this.count<=0)
    {
      
this.jump=0;
      
this.count=0;
    }
  }
  
//falling
  
if(!onwall(player.x+1player.y+3.55) && !onwall(player.x+1player.y+this.speed+.05) && !onwall(player.xplayer.y+3.55) && !onwall(player.xplayer.y+this.speed+.05) && !onwall(player.x+2player.y+3.55) && !onwall(player.x+2player.y+this.speed+.05))
  {
    if(!
this.jump==1)
    {
      
player.y+=this.speed;
    }
    if(
this.speed<5)
    {
      
this.speed+=.05;
    }
  }
  else  if(
onwall(player.x+1player.y+3.5) || onwall(player.x+1player.y+this.speed) || onwall(player.xplayer.y+3.5) || onwall(player.xplayer.y+this.speed) || onwall(player.x+2player.y+3.5) || onwall(player.x+2player.y+this.speed))
  {
    
this.speed=.05;
  }
  
settimer(.05);

Reply With Quote