Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-11-2011, 04:34 AM   #1
Bic
Fellow RPG Maker!
 
Join Date: Dec 2010
Location: Canada
Posts: 36
Send a message via AIM to Bic Send a message via MSN to Bic
Default [AS2] RPG Help

Trying to see if I can get a simple walking script for a character for a 2d rpg game.

Here is the download: mediafire.com/?to9m8tsnl6ncf3e

WASD to move the character

2 problems:


First of all, when I walk up, then stop, and up again, it won't do it's walking animation after I walk the same way as I did the first time.

Walk one way, stop, and walk the same way and it won't do it's animation.



Secondly, how can I get the character to face the mouse, as if I were to use the mouse to make him aim, catch my drift?
I ONLY want him to look at mouse when he is standing completely still, but if he moves he can't follow mouse.
Bic is offline   Reply With Quote
Old 05-11-2011, 11:02 PM   #2
David2.0
Member
 
David2.0's Avatar
 
Join Date: Feb 2011
Location: Virginia
Posts: 67
Send a message via MSN to David2.0
Default

Here's the code for direction:

ActionScript Code:
dir = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x)*180/(Math.PI)-90 //do some trial and error. Maybe you can make "dir" into a dynamic textbox and test it out that way if (dir > 90){ //blah }
David2.0 is offline   Reply With Quote
Old 05-11-2011, 11:55 PM   #3
Bic
Fellow RPG Maker!
 
Join Date: Dec 2010
Location: Canada
Posts: 36
Send a message via AIM to Bic Send a message via MSN to Bic
Default

Well I got the mouse aiming feature complete, unfortunately the char is ALWAYS facing the direction of the mouse. I only want it to face the mouse when it is not moving.

So can I make an if statement based on no keys being pressed?

Like... if (KeyisDown = false) {
}

or... if (! Keyis.Down) {
}

Is there osmething for that?

Last edited by Bic; 05-12-2011 at 12:24 AM.
Bic is offline   Reply With Quote
Old 05-12-2011, 12:21 AM   #4
David2.0
Member
 
David2.0's Avatar
 
Join Date: Feb 2011
Location: Virginia
Posts: 67
Send a message via MSN to David2.0
Default

It's all a matter of trial and error

It's best if you turn the degrees into a dynamic textbox, so you can see what degree it is.
David2.0 is offline   Reply With Quote
Old 05-12-2011, 12:38 AM   #5
Bic
Fellow RPG Maker!
 
Join Date: Dec 2010
Location: Canada
Posts: 36
Send a message via AIM to Bic Send a message via MSN to Bic
Default

Quote:
Originally Posted by David2.0 View Post
It's all a matter of trial and error

It's best if you turn the degrees into a dynamic textbox, so you can see what degree it is.

Alright, now I got this:
Code:
	if (!Key.isDown){
		if (angle>45 && angle<135){
			this.gotoAndStop("up");
		}
		else if (angle>135 && angle<225){
			this.gotoAndStop("left");
		}
		else if (angle>225 && angle<315){
			this.gotoAndStop("down");
		}
		else {
			this.gotoAndStop("right");
		}
	}
It works, besides the if(!Key.isDown) statement.

Without that, the mouse aiming thing works, but now with the if no key is down statement it won't work.

Also, how could I fix the moving animation problem?
I move one way (let's say down), stop then move the same way again the animation doesn't occur.

You will need to look at my code...
So here is the download:
mediafire.com/?r2a2dcaac46e44r

Last edited by Bic; 05-12-2011 at 12:41 AM.
Bic is offline   Reply With Quote
Old 05-12-2011, 12:50 AM   #6
David2.0
Member
 
David2.0's Avatar
 
Join Date: Feb 2011
Location: Virginia
Posts: 67
Send a message via MSN to David2.0
Default

Sorry, I'm on my school computer, which doesn't have flash ATM (people keep hogging it and use it for really dumb animations ), so you'll have to paste the code here.

Try doing the !Key.isDown for each key. I've seriously never seen it used that way (!Key.isDown(87)) people.uncw.edu/tompkinsj/112/flashactionscript/keycodes.htm)

Last edited by David2.0; 05-12-2011 at 12:55 AM. Reason: Smilies
David2.0 is offline   Reply With Quote
Old 05-12-2011, 01:08 AM   #7
Bic
Fellow RPG Maker!
 
Join Date: Dec 2010
Location: Canada
Posts: 36
Send a message via AIM to Bic Send a message via MSN to Bic
Default

Quote:
Originally Posted by David2.0 View Post
Sorry, I'm on my school computer, which doesn't have flash ATM (people keep hogging it and use it for really dumb animations ), so you'll have to paste the code here.

Try doing the !Key.isDown for each key. I've seriously never seen it used that way (!Key.isDown(87)) people.uncw.edu/tompkinsj/112/flashactionscript/keycodes.htm)
Oh shit, thanks! I'll try it out and let you know.
I'll post the code too.
Bic is offline   Reply With Quote
Old 05-12-2011, 01:11 AM   #8
David2.0
Member
 
David2.0's Avatar
 
Join Date: Feb 2011
Location: Virginia
Posts: 67
Send a message via MSN to David2.0
Default

Just a side note:

The reason why Flash doesn't have a one-in-all type of functions is because there are loopholes through that (i.e. holding down the SHIFT key that basically deactivates the hypothetical !Key.isDown, ruining the sprite's animation)
David2.0 is offline   Reply With Quote
Old 05-12-2011, 01:17 AM   #9
Bic
Fellow RPG Maker!
 
Join Date: Dec 2010
Location: Canada
Posts: 36
Send a message via AIM to Bic Send a message via MSN to Bic
Default

Here is all my code, it is on the actions layer.

Code:
// ATTACH TO CHARACTER LAYER
char = charLayer.attachMovie("character", "char", _root.getNextHighestDepth());

char.xSpeed = 0;
char.ySpeed = 0;

char.onEnterFrame = function() {
	
	// UP DOWN MOVEMENT
	if(Key.isDown(87)) {
		this.ySpeed = -6;
	}
	else if(Key.isDown(83)) {
		this.ySpeed = 6;
	}
	else {
		this.ySpeed = 0;
	}
	
	// LEFT RIGHT MOVEMENT
	if(Key.isDown(65)) {
		this.xSpeed = -6;
	}
	else if(Key.isDown(68)) {
		this.xSpeed = 6;
	}
	else {
		this.xSpeed = 0;
	}

	// 	WALKING ANIMATION
	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");
	}
	else (this.walk.gotoAndStop("stand"));
	this._x += this.xSpeed;
	this._y += this.ySpeed;
	
	// Mouse Face Stuff
	x = this._xmouse;
    y = this._ymouse*-1;
    angle = Math.atan(y/x)/(Math.PI/180);
	if (x<0) {
        angle += 180;
    }
    if (x>=0 && y<0) {
        angle += 360;
    }
	if (!Key.isDown(87)){
		if (angle>45 && angle<135){
			this.gotoAndStop("up");
		}
		else if (angle>135 && angle<225){
			this.gotoAndStop("left");
		}
		else if (angle>225 && angle<315){
			this.gotoAndStop("down");
		}
		else {
			this.gotoAndStop("right");
		}
	}
	

}

Last edited by Bic; 05-12-2011 at 01:24 AM.
Bic is offline   Reply With Quote
Old 05-12-2011, 01:23 AM   #10
David2.0
Member
 
David2.0's Avatar
 
Join Date: Feb 2011
Location: Virginia
Posts: 67
Send a message via MSN to David2.0
Cool Almost Nailed It

Code:
// ATTACH TO CHARACTER LAYER
char = charLayer.attachMovie("character", "char", _root.getNextHighestDepth());

char.xSpeed = 0;
char.ySpeed = 0;

char.onEnterFrame = function() {
	
	
	mx=_root._xmouse;
	my=_root._ymouse;
	
	var xmoving = false;
	var ymoving = false;

	
	// UP DOWN MOVEMENT
	if(Key.isDown(87)) {
		this.ySpeed = -6;
		var ymoving = true;
	}
	else if(Key.isDown(83)) {
		this.ySpeed = 6;
		var ymoving = true;
	}
	else {
		this.ySpeed = 0;
		var ymoving = false;
	}
	
	// LEFT RIGHT MOVEMENT
	if(Key.isDown(65)) {
		this.xSpeed = -6;
		var xmoving = true;
	}
	else if(Key.isDown(68)) {
		this.xSpeed = 6;
		var xmoving = true;
	}
	else {
		this.xSpeed = 0;
		var xmoving = false;
	}

	// 	WALKING ANIMATION
	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");
	}
	else (this.walk.gotoAndStop("stand"));
	this._x += this.xSpeed;
	this._y += this.ySpeed;
	
	// Mouse Face Stuff
	x = this._xmouse;
    y = this._ymouse*-1;
    angle = Math.atan(y/x)/(Math.PI/180);
	if (x<0) {
        angle += 180;
    }
    if (x>=0 && y<0) {
        angle += 360;
    }
	if (!Key.isDown(87)){
		if (angle>45 && angle<135){
			this.gotoAndStop("up");
		}
		else if (angle>135 && angle<225){
			this.gotoAndStop("left");
		}
		else if (angle>225 && angle<315){
			this.gotoAndStop("down");
		}
		else {
			this.gotoAndStop("right");
		}
	}
	

}
This reminds me of my RPG, except for the mouse facing stuff

Wouldn't the !Key.isDown(87) conflict with the other ones?

Because you could be pressing S and not pressing W at the same time
David2.0 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:08 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.