Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,521 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,816 people online right now. Registration is fast and FREE... Join Now!




Movement stop the way hes facing?

 
Reply to this topicStart new topic

Movement stop the way hes facing?

cadeownz
15 Aug, 2008 - 03:53 PM
Post #1

New D.I.C Head
*

Joined: 11 Jul, 2008
Posts: 31

Hey,
i have a character that moves if you press Up, Down, Left, Right, Up+Left ect.. but i dont know how to make him so when your walking say left and u stop he stops in a left standing stance not the one i have when hes just standing looking up. i have a left standing stance an up stance a right stance a down stance a up+left stance ect.. Any help? just to clarafy it i need to make him on key down LEFT gotoAndStop("walkleft") on keyrelease LEFT gotoAndStop("standleft") somthing like that.. Thnx heres the bit of the code that makes him walk left..
CODE
if (Key.isDown (Key.LEFT)) {
this.gotoAndStop("runL");
this._x -= 5;
}

so somehow i need on release of LEFT key gotoAndStop("stopL");
but i dont know how to do that in code..
help MUCH appreiciated..
thnx in advance...
biggrin.gif biggrin.gif smile.gif smile.gif biggrin.gif biggrin.gif smile.gif
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Movement Stop The Way Hes Facing?
15 Aug, 2008 - 06:23 PM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
What I would do is adda variable to the character that is something like var direction; and set that to the way he is walking (for instance, walkin gleft would give his direction as "left" and so on).

Then, if you are doing your movement inside of an onEnterFrame function you would just add an ending statement to the IFs so that if nothing is pressed (he is standing still) he will gotoAndStop("standing_"+direction). If that makes any sense.

HTH
User is offlineProfile CardPM
+Quote Post

cadeownz
RE: Movement Stop The Way Hes Facing?
15 Aug, 2008 - 08:18 PM
Post #3

New D.I.C Head
*

Joined: 11 Jul, 2008
Posts: 31

Hey,
that makes perfect sense but i do not know how to put that into code. i have no experience with Variables. can you teach me lol biggrin.gif
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Movement Stop The Way Hes Facing?
16 Aug, 2008 - 07:01 AM
Post #4

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
Okay, so place this variable in the player movieclip:

CODE

var dir;


Then, with your movement code it will look something like so:

CODE

if (Key.isDown (Key.LEFT) && Key.isDown(Key.UP)) {
this.gotoAndStop("runUL");
this._x -= 3.5355;
this._y -= 3.5355;
this.dir = "up_left";
}
else if(Key.isDown(Key.LEFT) && Key.isDownKey.DOWN)){
this.gotoAndStop("runDL");
this._x -= 3.5355;
this._y += 3.5355;
this.dir = "down_left";
}
else if(Key.isDown(Key.RIGHT) && Key.isDownKey.DOWN)){
this.gotoAndStop("runDR");
this._x += 3.5355;
this._y += 3.5355;
this.dir = "down_right";
}
else if(Key.isDown(Key.RIGHT) && Key.isDownKey.UP)){
this.gotoAndStop("runUR");
this._x += 3.5355;
this._y -= 3.5355;
this.dir = "up_right";
}
else if(Key.isDown(Key.LEFT)){
this.gotoAndStop("runL");
this._x -= 5;
this.dir = "left";
}
else if(Key.isDown(Key.RIGHT)){
this.gotoAndStop("runR");
this._x += 5;
this.dir = "right";
}
else if(Key.isDown(Key.UP)){
this.gotoAndStop("runU");
this._y -= 5;
this.dir = "up";
}
else if(Key.isDown(Key.DOWN)){
this.gotoAndStop("runD");
this._y += 5;
this.dir = "down";
}
else{
// not moving
this.gotoAndStop("standing_"+this.dir);
}


Hope that helsp.

REALIZE - this is assuming that the above code is withing th eplayer MC as well.
User is offlineProfile CardPM
+Quote Post

flashnoob
RE: Movement Stop The Way Hes Facing?
18 Aug, 2008 - 02:40 PM
Post #5

New D.I.C Head
*

Joined: 18 Aug, 2008
Posts: 3

hmm
User is offlineProfile CardPM
+Quote Post

cadeownz
RE: Movement Stop The Way Hes Facing?
23 Aug, 2008 - 07:44 PM
Post #6

New D.I.C Head
*

Joined: 11 Jul, 2008
Posts: 31

THANK U SO MUCH!
oh and im sorry i havent been on in ages i just had other stuff to do... biggrin.gif
so now i got it walking and stoping the way he was walking last.. BUT he stays walking coz it refers only to him walking is there anyway to make it like on keyUp go to stopU coz keyUp is an onClipEvent command.. Help MUCH x1000000000 appreiciated biggrin.gif biggrin.gif but yeah thnx!
biggrin.gif biggrin.gif smile.gif smile.gif biggrin.gif biggrin.gif smile.gif smile.gif biggrin.gif biggrin.gif biggrin.gif smile.gif smile.gif biggrin.gif biggrin.gif
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Movement Stop The Way Hes Facing?
23 Aug, 2008 - 08:50 PM
Post #7

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
I am not quite sure what you are talking about here, maybe try to specify a bit more...

But I think the script above already does soemthing liek what you are talking about. The player is moving in a certain direction as long as a key is down, if no keys are down (at least none of the ones that we have a movement action attached to) the player is told to gotoAndStop("standing_"+this.dir); hich we are setting to whatever direction the player is facing...
User is offlineProfile CardPM
+Quote Post

cadeownz
RE: Movement Stop The Way Hes Facing?
24 Aug, 2008 - 10:30 PM
Post #8

New D.I.C Head
*

Joined: 11 Jul, 2008
Posts: 31

Ok,
My character has like a walking animation. so when u press a key he starts walking. and when u release he doesent move, stays in the same place BUT he is still doing the alking animation. do u get wat i mean?
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Movement Stop The Way Hes Facing?
25 Aug, 2008 - 04:33 AM
Post #9

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
Yes, now I understand. Can I see what coe you are using for his movement?
User is offlineProfile CardPM
+Quote Post

cadeownz
RE: Movement Stop The Way Hes Facing?
25 Aug, 2008 - 08:07 PM
Post #10

New D.I.C Head
*

Joined: 11 Jul, 2008
Posts: 31

Its just what the code above is, but here is the complete walking bit.
NOTE: its birds eye view and the guy doesnt move the background moves so this is the characters code. Im sure it will go in here..
CODE
onClipEvent (enterFrame) {
if (Key.isDown (Key.RIGHT)) {
this.gotoAndStop("runR");
this.dir = "runR";
}
if (Key.isDown (Key.LEFT)) {
this.gotoAndStop("runL");
this.dir = "runL";
}  
if (Key.isDown (Key.UP)) {
this.gotoAndStop("runU");
this.dir = "runU";
}
if (Key.isDown (Key.CONTROL)){
this.gotoAndStop("shoot");
}
if (Key.isDown (Key.DOWN)){
this.gotoAndStop("runD");
this.dir = "runD";
}
if(Key.isDown(Key.UP)&&Key.isDown(Key.LEFT)){
this.gotoAndStop("runUL");
this.dir = "runUL";
}
if(Key.isDown(Key.UP)&&Key.isDown(Key.RIGHT)){
this.gotoAndStop("runUR");
this.dir = "runUR";
}
if(Key.isDown(Key.DOWN)&&Key.isDown(Key.RIGHT)){
this.gotoAndStop("runDR")
this.dir = "runDR";
}
if(Key.isDown(Key.DOWN)&&Key.isDown(Key.LEFT)){
this.gotoAndStop("runDL");
this.dir = "runDL";
}
if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.LEFT)){
this.gotoAndStop("standing_"+this.dir);
}
if(Key.isDown(Key.DOWN)&&Key.isDown(Key.UP)){
this.gotoAndStop("standing_"+this.dir);
}
if(Key.isDown(Key.DOWN)&&Key.isDown(Key.LEFT)&&Key.isDown(Key.RIGHT)){
this.gotoAndStop("standing_"+this.dir);
}
if(Key.isDown(Key.DOWN)&&Key.isDown(Key.UP)&&Key.isDown(Key.RIGHT)){
this.gotoAndStop("standing_"+this.dir);
}
}
onClipEvent (keyUp) {
this.gotoAndStop("standing_"+this.dir);
}


This post has been edited by cadeownz: 25 Aug, 2008 - 08:11 PM
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Movement Stop The Way Hes Facing?
25 Aug, 2008 - 08:30 PM
Post #11

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
Okay try using this:

CODE
onClipEvent (enterFrame) {
if(Key.isDown(Key.UP)&&Key.isDown(Key.LEFT)){
this.gotoAndStop("runUL");
this.dir = "runUL";
}
else if(Key.isDown(Key.UP)&&Key.isDown(Key.RIGHT)){
this.gotoAndStop("runUR");
this.dir = "runUR";
}
else if(Key.isDown(Key.DOWN)&&Key.isDown(Key.RIGHT)){
this.gotoAndStop("runDR")
this.dir = "runDR";
}
else if(Key.isDown(Key.DOWN)&&Key.isDown(Key.LEFT)){
this.gotoAndStop("runDL");
this.dir = "runDL";
}

else if (Key.isDown (Key.RIGHT)) {
this.gotoAndStop("runR");
this.dir = "runR";
}
else if (Key.isDown (Key.LEFT)) {
this.gotoAndStop("runL");
this.dir = "runL";
}  
else if (Key.isDown (Key.UP)) {
this.gotoAndStop("runU");
this.dir = "runU";
}
else if (Key.isDown (Key.CONTROL)){
this.gotoAndStop("shoot");
}
else if (Key.isDown (Key.DOWN)){
this.gotoAndStop("runD");
this.dir = "runD";
}

else{
this.gotoAndStop("standing_"+this.dir);
}

}
onClipEvent (keyUp) {
this.gotoAndStop("standing_"+this.dir);
}


That should work (Note, I did change around the code a little from what you originally had to do the multi-directional checks first then do single direction checks and if nothing else works have the character stand still. This will also make it so that things like holding Left and Right will count as only holding Right.)

Hope that works out for you.

This post has been edited by BetaWar: 25 Aug, 2008 - 08:30 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 09:32PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month