Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Gravity (https://forums.graalonline.com/forums/showthread.php?t=68152)

excaliber7388 08-17-2006 05:27 AM

Gravity
 
Bah, I can't figure out what's wrong here. It started out as a clean looking script, but I had to add quite a few extra checks. Anyway, this is what I have now. Sometimes I am able to jump fine, other times it's a short jump. And sometimes when I land, I bounce, or go below the ground. I thought I had it all checked out. I don't want a free script, just tell me what I'm missing with this one :\
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;
  
settimer(.05);
}
function 
onTimeout()
{
  
//set the jump
  
if(keydown(0) && this.jump==&& onwall(player.x+1player.y+3.5))
  {
    
this.speed=.05;
    
this.jump=1;
    
this.count=50;
  }
  
//force fall
  
if(keydown(2))
  {
    if(!
onwall(player.x+1player.y+3.5))
    {
      
this.speed+=.5;
    }
  }
  
//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
    {
      
this.count=0;
    }
    
this.count--;
    if(
this.count<=0)
    {
      
this.jump=0;
    }
  }
  if(!
onwall(player.x+1player.y+3.5))
  {
    
player.y+=this.speed;
    if(
this.speed<5)
    {
      
this.speed+=.05;
    }
  }
  else if(
onwall(player.x+1player.y+3.5))
  {
    
this.speed=.05;
  }
  
settimer(.05);



Yen 08-17-2006 08:08 AM

Use a for() to check every pixel for blockage between where the player is and where the player is moving to in the next step. When the player is blocked, move the player to the previous pixel.

excaliber7388 08-17-2006 03:49 PM

Though I may take that into consideration, I doubt that's what's causing the inability to jump (though it may help with the bouncing/going underground thing)

excaliber7388 08-17-2006 10:45 PM

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);




All times are GMT +2. The time now is 05:04 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.