[RESOLVED] [CS3] Click then Walk
Attached Files
Last edited by humbuged; 09-06-2008 at 10:06 AM .
I found out a code and I figured out how to set a constant speed. But the guy shakes when he reaches the target :O Here's what I coded;
Code:
moveGuy = function () {
this.dx = (this.targx-this._x);
this.dy = (this.targy-this._y);
distance = Math.sqrt(this.dx*this.dx+this.dy*this.dy);
this.vx = (this.dx/distance)*speed;
this.vy = (this.dy/distance)*speed;
this._x += this.vx;
this._y += this.vy;
};
setTarget = function () {
this.targx = _root._xmouse;
this.targy = _root._ymouse;
};
speed = 6;// adjust as required
guy.onEnterFrame = moveGuy;
guy.onMouseDown = setTarget;
Oh, I think I got it It works but I'm a bit unsure;
Code:
moveGuy = function () {
this.dx = (this.targx-this._x);
this.dy = (this.targy-this._y);
distance = Math.sqrt(this.dx*this.dx+this.dy*this.dy);
this.vx = (this.dx/distance)*speed;
this.vy = (this.dy/distance)*speed;
if (distance<4) {
this.vx = 0;
this.vy = 0;
}
this._x += this.vx;
this._y += this.vy;
};
setTarget = function () {
this.targx = _root._xmouse;
this.targy = _root._ymouse;
};
speed = 7;// adjust as required
guy.onEnterFrame = moveGuy;
guy.onMouseDown = setTarget;
Now how to I make him stop if he gets near the black square?
Hmm, I got him to stop when hits the black wall, but then he won't move after clicking elsewhere :B
Code:
moveGuy = function () {
trace(distance);
this.dx = (this.targx-this._x);
this.dy = (this.targy-this._y);
distance = Math.sqrt(this.dx*this.dx+this.dy*this.dy);
this.vx = (this.dx/distance)*speed;
this.vy = (this.dy/distance)*speed;
if (this.hitTest(_root.wall) == true) {
this.vx = 0;
this.vy = 0;
} else {
if (distance<4) {
this.vx = 0;
this.vy = 0;
}
}
this._x += this.vx;
this._y += this.vy;
};
setTarget = function () {
this.targx = _root._xmouse;
this.targy = _root._ymouse;
};
speed = 7;// adjust as required
guy.onEnterFrame = moveGuy;
guy.onMouseDown = setTarget;
Any suggestions?
This didn't work, he keeps going to the upper left or something :O
http://www.swfupload.com/view/100910.htm
Code:
moveGuy = function () {
this.dx = (this.targx-this._x);
this.dy = (this.targy-this._y);
distance = Math.sqrt(this.dx*this.dx+this.dy*this.dy);
this.vx = (this.dx/distance)*speed;
this.vy = (this.dy/distance)*speed;
if (this.hitTest(_root.wall) == true) {
this.vx = 0;
this.vy = 0;
this._x -= 5;
this._y -= 5;
} else {
if (distance<4) {
this.vx = 0;
this.vy = 0;
}
}
this._x += this.vx;
this._y += this.vy;
};
setTarget = function () {
this.targx = _root._xmouse;
this.targy = _root._ymouse;
};
speed = 7;// adjust as required
guy.onEnterFrame = moveGuy;
guy.onMouseDown = setTarget;
I found this nice point & click walking method: http://board.flashkit.com/board/showthread.php?t=767920
His characters can only walk on a certain pathway. How do I do this? I've tried looking at his .fla but my beginner's knowledge can't decipher it XD It's also in Spanish :P
Pls, help
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width