Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Simple Movement (https://forums.graalonline.com/forums/showthread.php?t=77055)

Angel_Light 10-06-2007 08:08 AM

Simple Movement
 
Here is a good way to move your object in all directions very easily.

PHP Code:

//#CLIENTSIDE  // Makes events all processed on the client comp

function onCreated()  //Action is called when script is read
{

  
disAbleDefMovement();  //Disables Default movement for player
}

function 
onKeyPressedcodechar)  //Called when ever the client pushes a key on the keyboard
{

  
code;  //make k equal the code number of what ever key is pushed

  
player.+= (( == 39) - ( == 37))/16;  //  if k equals number, it is 1, if not it is 0

  //so if the player pushes left arrow it be player.x += 0 - 1;  

  
player.+= (( == 40) - ( == 38))/16;  //same as above just on the y-axis




DustyPorViva 10-06-2007 08:15 AM

Hmm, there's a problem with this.
One, there's no loop, you're calling it on keypressed(unless you want it to be a more systematic movement than fluid). As I believe, keypressed is called when the key is first pressed, then the repeat(which is defined personally in the keyboard properties, so this will react very slowly if the person has the key repeat very low). Also, I think it'd be better if you used keydown(0-3), they're the default keys for arrow movement, and are also compatible with gamepads.

Angel_Light 10-06-2007 08:21 AM

Update


PHP Code:

//#CLIENTSIDE 

function onCreated()
{

  
disAbleDefMovement();
  
onTimeout();
}

function 
onTimeout()
{

  
player.+= (( keydown(3)) - ( keydown(1)))/16;  

  
player.+= (( keydown(2)) - ( keydown(0)))/16;  

  
setTimer0.05);



Crow 10-06-2007 09:14 AM

Do you want to add some onwall checks later? :]

Inverness 10-06-2007 10:43 AM

Disable is one word -.-

disableDefMovement();

instead of disAbleDefMovement();

Angel_Light 10-06-2007 07:18 PM

Quote:

Originally Posted by Crow (Post 1351276)
Do you want to add some onwall checks later? :]

Not, really, guess I could but I just wanted to show how to move an object.


Quote:

Originally Posted by Inverness (Post 1351281)
Disable is one word -.-

disableDefMovement();

instead of disAbleDefMovement();

I know, I like to capitalize the A so i can simple delete the dis and put in the en.

Crow 10-06-2007 07:42 PM

Quote:

Originally Posted by Angel_Light (Post 1351357)
I know, I like to capitalize the A so i can simple delete the dis and put in the en.

You could do that without a capital A ;P
Anyways, I think you should add the checks, just for the sake of it. May help out some peeps.

Angel_Light 10-06-2007 07:55 PM

Quote:

Originally Posted by Crow (Post 1351360)
You could do that without a capital A ;P
Anyways, I think you should add the checks, just for the sake of it. May help out some peeps.

It doesnt really matter how the A is...

update

PHP Code:

//#CLIENTSIDE 

function onCreated()
{

  
disAbleDefMovement();
  
onTimeout();
}

function 
onTimeout()
{
  
  
nx player.x;
  
ny player.y;

  
nx += (( keydown(3)) - ( keydown(1)))/16;  
  
ny += (( keydown(2)) - ( keydown(0)))/16;  

  if ( !( 
onwallnx 1.5ny 2)))  {

    
player.nx;
    
player.ny;
  } 

  
setTimer0.05);



Crow 10-06-2007 08:06 PM

I would atleast define the middle of the player ;P

PHP Code:

if ( !( onwallnx 1.5ny 2)))  {

  
player.nx;
  
player.ny;




All times are GMT +2. The time now is 10:12 PM.

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