PDA

View Full Version : Simple Movement


Angel_Light
10-06-2007, 09:08 AM
Here is a good way to move your object in all directions very easily.


//#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 onKeyPressed( code, char) //Called when ever the client pushes a key on the keyboard
{

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

player.x += (( k == 39) - ( k == 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.y += (( k == 40) - ( k == 38))/16; //same as above just on the y-axis

}

DustyPorViva
10-06-2007, 09: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, 09:21 AM
Update



//#CLIENTSIDE

function onCreated()
{

disAbleDefMovement();
onTimeout();
}

function onTimeout()
{

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

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

setTimer( 0.05);
}

Crow
10-06-2007, 10:14 AM
Do you want to add some onwall checks later? :]

Inverness
10-06-2007, 11:43 AM
Disable is one word -.-

disableDefMovement();

instead of disAbleDefMovement();

Angel_Light
10-06-2007, 08:18 PM
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.


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, 08:42 PM
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, 08:55 PM
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


//#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 ( !( onwall( nx + 1.5, ny + 2))) {

player.x = nx;
player.y = ny;
}

setTimer( 0.05);
}

Crow
10-06-2007, 09:06 PM
I would atleast define the middle of the player ;P

if ( !( onwall( nx + 1.5, ny + 2))) {

player.x = nx;
player.y = ny;
}