Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Programming Exercise #6: The Ice Script (https://forums.graalonline.com/forums/showthread.php?t=82422)

Kristi 10-20-2008 05:17 PM

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...

WhiteDragon 11-29-2008 08:55 PM

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 


Bl0nkt 12-01-2008 05:35 AM

Are we limited to local NPC scripts, can we use weapons, a combination of the two?

cbk1994 12-01-2008 05:49 AM

Quote:

Originally Posted by Bl0nkt (Post 1445879)
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?

xXziroXx 12-01-2008 04:09 PM

Quote:

Originally Posted by cbk1994 (Post 1445883)
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.

Bl0nkt 12-01-2008 08:53 PM

Quote:

Originally Posted by cbk1994 (Post 1445883)
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.

cbk1994 12-01-2008 11:22 PM

Quote:

Originally Posted by xXziroXx (Post 1445943)
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 (Post 1446009)
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.

WhiteDragon 12-02-2008 03:13 AM

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.

Kristi 12-05-2008 07:04 PM

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:D)


All times are GMT +2. The time now is 09:20 AM.

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