Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-17-2006, 05:27 AM
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
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);

Reply With Quote
  #2  
Old 08-17-2006, 08:08 AM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
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.
Reply With Quote
  #3  
Old 08-17-2006, 03:49 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
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)
Reply With Quote
  #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
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:18 PM.


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