PDA

View Full Version : Damn move()


Raeiphon
01-21-2007, 12:12 PM
this.movex = playerx - x; // x needed to travel to player
this.movey = playery - y; // y needed to travel to player
if (player.dir=1){ this.desx = 1.7; this.desy = 1; }
if (player.dir=0) { this.desx = -1.7; this.desy = 1; }
if (player.dir=2) { this.desx = 1.7; this.desy = -1.7; }
if (player.dir=3) { this.desx = -1.7; this.desy = -1.7; }
setCharAni("walk","");
move(this.movex+this.desx,this.movey+this.desy,1,1 );
setCharAni("idle","");


Inefficient, I know, but it gets the job done.

Basically, it's supposed to move the npc so it looks like it's standing next to me. Problem is, i'm an aesthetics freak, and the fact that it just glides along concerns me. How would I go about making the npc use the walk gani through the move sequence?

Chandler
01-21-2007, 12:32 PM
function onCreated()
{
this.showCharacter();

this.curPlayer = findPlayer("cHANDLER");
this.onTimeout();
}
function onTimeout()
{
temp.movex = this.curPlayer.x - x; // x needed to travel to player
temp.movey = this.curPlayer.y - y; // y needed to travel to player
dir = getdir(temp.movex, temp.movey);

if (player.dir == 1) { this.desx = 1.7; this.desy = 1; }
if (player.dir == 0) { this.desx = -1.7; this.desy = 1; }
if (player.dir == 2) { this.desx = 1.7; this.desy = -1.7; }
if (player.dir == 3) { this.desx = -1.7; this.desy = -1.7; }

this.ani = "walk";
move((temp.movex + this.desx), (temp.movey + this.desy), 1, 1);
}
function onMovementFinished()
{
this.ani = "idle";
this.onTimeout();
}

Mainly, you should focus on the "onMovementFinished()" function.
That's how I was testing it, however it wasn't finishing the movement. (Wasn't calling "onMovementFinished()")

Chompy
01-21-2007, 05:26 PM
function onCreated()
{
this.showCharacter();

this.curPlayer = findPlayer("cHANDLER");
this.onTimeout();
}
function onTimeout()
{
temp.movex = this.curPlayer.x - x; // x needed to travel to player
temp.movey = this.curPlayer.y - y; // y needed to travel to player
dir = getdir(temp.movex, temp.movey);

if (player.dir == 1) { this.desx = 1.7; this.desy = 1; }
if (player.dir == 0) { this.desx = -1.7; this.desy = 1; }
if (player.dir == 2) { this.desx = 1.7; this.desy = -1.7; }
if (player.dir == 3) { this.desx = -1.7; this.desy = -1.7; }

this.ani = "walk";
move((temp.movex + this.desx), (temp.movey + this.desy), 1, 1);
}
function onMovementFinished()
{
this.ani = "idle";
this.onTimeout();
}

Mainly, you should focus on the "onMovementFinished()" function.
That's how I was testing it, however it wasn't finishing the movement. (Wasn't calling "onMovementFinished()")

You need to add 8 to the move options to trigger that.

And, for better, and smooth movement (time wise),
use this:


dist = ( dx ^ 2 + dy ^ 2) ^ 0.5;
move( dx, dy, dist / tilespersecond, flags);

konidias
01-21-2007, 05:32 PM
function onCreated()
{
this.showCharacter();

this.curPlayer = findPlayer("cHANDLER");
this.onTimeout();
}
function onTimeout()
{
temp.movex = this.curPlayer.x - x; // x needed to travel to player
temp.movey = this.curPlayer.y - y; // y needed to travel to player
dir = getdir(temp.movex, temp.movey);

if (player.dir == 1) { this.desx = 1.7; this.desy = 1; }
if (player.dir == 0) { this.desx = -1.7; this.desy = 1; }
if (player.dir == 2) { this.desx = 1.7; this.desy = -1.7; }
if (player.dir == 3) { this.desx = -1.7; this.desy = -1.7; }

this.ani = "walk";
move((temp.movex + this.desx), (temp.movey + this.desy), 1, 8+16);
}
function onMovementFinished()
{
this.ani = "idle";
this.onTimeout();
}


Like that. The 8 in bold means "inform when done" which lets you use "onMovementFinished". The 16 is for making sure the npc faces the direction it's moving. Otherwise it's just gonna be facing down or whatever while it walks.

Raeiphon
01-22-2007, 04:35 AM
It's still stuck on the walk gani even when it's supposed to be idling.

onMovementFinished doesn't appear to be called, even with 8+16

EDIT: Fixed. This works.


function onCreated()
{
this.showCharacter();

this.curPlayer = findPlayer("Raeiphon");
this.onTimeout();
}
function onTimeout()
{
temp.movex = this.curPlayer.x - x; // x needed to travel to player
temp.movey = this.curPlayer.y - y; // y needed to travel to player
dir = getdir(temp.movex, temp.movey);

if (player.dir == 1) { this.desx = 1.7; this.desy = 1; }
if (player.dir == 0) { this.desx = -1.7; this.desy = 1; }
if (player.dir == 2) { this.desx = 1.7; this.desy = -1.7; }
if (player.dir == 3) { this.desx = -1.7; this.desy = -1.7; }
if (this.curPlayer.x+this.desx!=x) {
this.ani = "walk";
move((temp.movex + this.desx), (temp.movey + this.desy), 1, 8+16);
} else {
this.ani = "idle";
setTimer(.05);
}
}
function onPlayerChats() {
if (player.chat="dismiss") {
destroy();
}
}
function onMovementFinished()
{
this.ani = "idle";
setTimer(.05);

coreys
01-22-2007, 06:30 AM
And, for better, and smooth movement (time wise),
use this:


dist = ( dx ^ 2 + dy ^ 2) ^ 0.5;
move( dx, dy, dist / tilespersecond, flags);

Yay basic geometry! One of the few equations from Geometry I actually remember.

But yeah, I never really liked move(). Not for any particular reason really...o.o.