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 11-15-2011, 12:30 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Car Movements Help

I am working on a "Car" for Graal Ghetto and so far all I have is the movement.
For my example I have added a block image to show the "Car".
Although the movement is working perfectly the acceleration isn't.
The problem is when accelerating if you turn it stops accelerating.
Here is what I have so far.
I am entrusting that the Graal community will NOT steal this, as I have spent about an hour and a half just getting this much.
2330 Characters long and 87 lines.
Thanks.
PHP Code:
/*
Scripted by Gunderak.
Intended to be used on Graal Ghetto and Graal Ghetto ONLY.
You may however study this and try to learn from it.
*/
//#CLIENTSIDE
function onCreated() {
  
//Disables default movement.
  
disabledefmovement();
  
//Speed variables
  
this.speed "1";
  
this.leftrightspeed "0.13";
  
this.movespeed "0";
  
this.acceleration "0.10";
  
//Begins the timeout.
  
onTimeout();
}

function 
GraalControl.onKeyDown(code) {
   
//If the Right-arrow key is pressed.
  
if (code == 37) {
    
//And if the car is moving.
    //This makes car movements seem more realistic.
    
if (this.movespeed 0) {
      
//Raises the angle.
      
this.dir += this.leftrightspeed;
    }
  }
  
//If the left-arrow key is pressed.
  
if (code == 39) {
    
//And if the car is moving.
    //This makes car movements seem more realistic.
    
if (this.movespeed 0) {
      
//Lowers the angle.
      
this.dir -= this.leftrightspeed;
    }
  }
  
//If the up-arrow key is released.
  
if(code == "38"){
  
//Start moving the car and begin to accelerate.
  
this.moving 1;
  }
}

function 
GraalControl.onKeyUp(code){
  
//If the up-arrow key is released.
  
if(code == 38){
   
//Stop moving the car and begin to decelerate.
   
this.moving 0;
  }
}

function 
onTimeout() {
  
//Shows a block image.
  
showimg(3"block.png"player.xplayer.);
  
//Changes the blocks rotation to the correct angle.
  
findimg(3).rotation this.dir;
  
findimg(3).zoom 2;
  
//If the angle is less than the minimum resets it to zero.
  
if (this.dir "-6.25") {
    
this.dir 0;
  }
  
//If the angle is greater than the maximum resets it to zero.
  
if (this.dir "6.25") {
    
this.dir 0;
  }
  
//Just some basic Trigonometry.
  //This part has been removed.
  //If you really want to steal this script you will have to
  //figure the sine and cosine out yourself!
  //If the car isnt accelerating slowly decrease speed.
  
if (this.moving == 0) {
    
this.movespeed -= this.acceleration 3;
  } else {
    if (
this.movespeed this.speed) {
      
this.movespeed += this.acceleration;
    }
  }
  
//If your move speed is less than zero for some reason
  //It will set it back to zero.
  
if (this.movespeed 0) {
    
this.movespeed 0;
  }
  
//Continues to loop through the timeout.
  
settimer(0.05);

Update
Removed the players movement seeming as it isn't necessary.
Also to make it harder for people to steal this script and actually use it.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 11-15-2011 at 01:08 PM..
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 12:44 PM.


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