Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-20-2008, 05:17 PM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Programming Exercise #6: The Ice Script

In lieu of: http://forums.graalonline.com/forums...ad.php?t=82343
As I find this topic very interesting:

Graal ice scripts historically have absolutely arbitrary physics. I think that perhaps we need to really evaluate how we make ice skating scripts.

This is what I propose:
Anyone who wants to participate in this exercise will make an ice skating script based on basic movement (disable it in your script if you choose).

I will later today talk with one of the classic server managers to set up a place to upload all these ice scripts, so that each room has a separate ice script for each entry you guys give here. We shall update this ice script house as entries come in.

You all will be able to go skate in these rooms and look at the scripts.

I think we need to look at this with two concepts (two sets of physics):
Program what you think would happen with ice skates on,
and program what you think would happen with normal shoes on.

And the scantily clad babe drops the flag to start...
__________________
Reply With Quote
  #2  
Old 11-29-2008, 08:55 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Here's my entry...
Basically, there are a few coefficients that you can tweak at the top to change how it acts and probably get a bit closer to "real" than what I did, but the physics are pretty exact.
I did take a whole lot of things out of what real ice skating physics would be because we only have a certain level of control (i.e., we can't change what angles the skates are pointing at or exactly how much power we want per stroke), but I made a few estimations as to how to replicate what a normal person would do.

And the code:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
disabledefmovement();
  
  
this.velocity = {0,0,0}; // inital velocity vector
  
  
this.power 1// power per stroke (should be less than 1 or you might get weird results)
  
this.friction .95// friction coefficient
  
this.collision = -.5// collision coefficient

  
this.scale .5// velocity -> tiles

  
this.foot 1// current foot

  
onTimeout();
}

function 
onTimeout() {
  if (
keydown(0) || keydown(1) || keydown(2) || keydown(3)) { // if a key is pressed
    
if (this.cooldown <= 0) { // if the cooldown is finished
    
      // alternate current foot
      
this.foot = -this.foot;

      
// set the ani, would make more sense if I had one for each foot, but just sticking with defaults
      
setani("walk"null);
      
      
// set the direction
      
player.dir getdir((keydown(3)-keydown(1)), (keydown(2)-keydown(0)));

      
// normalized movement vector based on key input
      
temp.movement vectornormalize({(keydown(3)-keydown(1)), (keydown(2)-keydown(0)), 0});
      
      
// rotate movement vector slightly based on which foot the stroke is coming from and how fast the player is traveling
      
temp.movement getvectorfromangles(getanglesfromvector(temp.movement)[0]+this.foot*vectorlen(this.velocity)^2.5/80);
      
      
// scale movement vector
      
temp.movement vectorscale(temp.movementthis.power);

      
// add the movement vector to the player velocity vector
      
this.velocity vectoradd(this.velocitytemp.movement);
      
      
// add a cooldown variable until next stroke based on how fast the player is traveling
      
this.cooldown int(vectorlen(this.velocity)*2);
    } else { 
      
setani("idle"null);
    }
  } else {
    
setani("idle"null);
  }
  
this.cooldown--; // decrease cooldown

  
if (vectorlen(this.velocity) < .1) { // just so it doesn't do a bunch of calculations for more or less no reason
    
this.velocity = {0,0,0};
  } else {
    
this.velocity vectorscale(this.velocitythis.friction); // apply the friction coefficient

    // collision detection

    
temp.7;
    for (
temp.1temp.<= temp.ttemp.i++) { // partition the checking into temp.t parts
      
      // if the next point is not on a wall
      
if (!onwall2(player.x+((this.velocity[0]*this.scale)/temp.t), player.y+((this.velocity[1]*this.scale)/temp.t), 23)) {
        
// move onto the next point
        
player.+= (this.velocity[0]*this.scale)/temp.t;
        
player.+= (this.velocity[1]*this.scale)/temp.t;
      } else {
        
// scale the vector with the collision coefficient
        
this.velocity vectorscale(this.velocitythis.collision);
      }
    }
  }
  
setTimer(0.05);

The coefficients I set should more or less replicate a player with ice skates on.

For a player with ice skates off I would probably use the following constants:
PHP Code:
  this.power .1// power per stroke (should be less than 1 or you might get weird results)
  
this.friction .99// friction coefficient
  
this.collision = -.1// collision coefficient 
Reply With Quote
  #3  
Old 12-01-2008, 05:35 AM
Bl0nkt Bl0nkt is offline
Era Developer
Bl0nkt's Avatar
Join Date: Mar 2005
Location: Pennsylvania
Posts: 1,589
Bl0nkt will become famous soon enough
Send a message via AIM to Bl0nkt
Are we limited to local NPC scripts, can we use weapons, a combination of the two?
Reply With Quote
  #4  
Old 12-01-2008, 05:49 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Bl0nkt View Post
Are we limited to local NPC scripts, can we use weapons, a combination of the two?
Why would you need to use anything other than a weapon script?
__________________
Reply With Quote
  #5  
Old 12-01-2008, 04:09 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by cbk1994 View Post
Why would you need to use anything other than a weapon script?
If it's limited to say, a skate park, I'd just put the script in the level.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #6  
Old 12-01-2008, 08:53 PM
Bl0nkt Bl0nkt is offline
Era Developer
Bl0nkt's Avatar
Join Date: Mar 2005
Location: Pennsylvania
Posts: 1,589
Bl0nkt will become famous soon enough
Send a message via AIM to Bl0nkt
Quote:
Originally Posted by cbk1994 View Post
Why would you need to use anything other than a weapon script?
A local NPC script to define the icy area including the variables for its slipperiness and the weapon which is always active and acts based upon the variables.
Reply With Quote
  #7  
Old 12-01-2008, 11:22 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xXziroXx View Post
If it's limited to say, a skate park, I'd just put the script in the level.
In a class or something, right?
Quote:
Originally Posted by Bl0nkt View Post
A local NPC script to define the icy area including the variables for its slipperiness and the weapon which is always active and acts based upon the variables.
Oh, I see what you mean.
__________________
Reply With Quote
  #8  
Old 12-02-2008, 03:13 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Frankly, I don't think it matters how it's implemented. I think what the programming exercise is focused on is the physics and realism.
For example, my script could be tweaked in under a minute to communicate with a class rather than from predefined constants, but it would really have nothing to do with what this programming exercise was designed for. More or less, I'm just trying to say I was aiming to keep it both simple and concise.
Reply With Quote
  #9  
Old 12-05-2008, 07:04 PM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
I will start this today, thanks to WhiteDragon.

Any other entries? More to follow.

(I hope everyone had a happy thanksgiving to balance out a terrible one of mine)
__________________
Reply With Quote
Reply

Tags
physics, programming-exercise

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 06:53 PM.


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