Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-10-2002, 07:22 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Small Movement Script

I started working on a movement script which lets you steer using the left/right keys and accelerate with up/down.
It's meant for underwater/swimming movement.
Do you people think that it's usable, or should I change it's behaviour?

NPC Code:
//#CLIENTSIDE
if (created) {
this.playerdir = 1;
timeout = 0.05;
}
if (timeout) {
disabledefmovement;
// Steering left/right
// Changing the dir
if (keydown(1)) this.playerdir += 0.05;
if (keydown(3)) this.playerdir -= 0.05;
this.playerdir = this.playerdir%2;
// Calculating the actual angle
angle = 3.14159265 * this.playerdir;
// Displaying the current direction
showimg 0,@tempus sans itc@cb@X,playerx+1.5+xmove,playery+2+ymove;
// Accelerating
// Calculating current direction
xmove = sin(angle);
ymove = cos(angle);
// Adding speed into a direction
if (keydown(0)) {
this.xspeed += xmove/5;
this.yspeed += ymove/5;
}
if (keydown(2)) {
this.xspeed -= xmove/20;
this.yspeed -= ymove/20;
}
// Limiting the speed
if (this.xspeed>0.5) this.xspeed = 0.5;
if (this.yspeed>0.5) this.yspeed = 0.5;
if (this.xspeed<-0.5) this.xspeed = -0.5;
if (this.yspeed<-0.5) this.yspeed = -0.5;
// Moving the player
playerx += this.xspeed;
playery += this.yspeed;
// Slowing down a bit
this.xspeed *= 0.99;
this.yspeed *= 0.99;
// Displaying the speed
setplayerprop #c,#v(this.xspeed) #v(this.yspeed);
timeout = 0.05;
}

Reply With Quote
 


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:51 PM.


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