-
Character Sprites Following mouse with delay
I am currently making a game where the character would follow the mouse on screen. I currently have the character moving with the use of the arrow keys but i am lost to as how to make the character follow and face the mouse.
_root.attachMovie("char","char",_root.getNextHighe stDepth());
char.xSpeed = 0;
char.ySpeed = 0;
char.onEnterFrame = function(){
if(Key.isDown(Key.UP)){
trace("UP");
this.ySpeed = -3;
}
else if(Key.isDown(Key.DOWN)){
trace("DOWN");
this.ySpeed = 3;
}
else {
this.ySpeed = 0;
}
if(Key.isDown(Key.LEFT)){
trace("LEFT");
this.xSpeed = -3;
}
else if(Key.isDown(Key.RIGHT)){
trace("RIGHT");
this.xSpeed = 3;
}
else {
this.xSpeed = 0;
}
if(this.xSpeed < 0) {
char.gotoAndStop("right");
}
else if(this.xSpeed > 0){
char.gotoAndStop("left");
}
else if(this.ySpeed > 0) {
char.gotoAndStop("down");
}
else if(this.ySpeed < 0) {
char.gotoAndStop("up")
}
this._x += this.xSpeed;
this._y += this.ySpeed;
}
this is what I have, could anyone help please
Thanks.
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
|