Welcome Guest [Log In] [Register]
Welcome to Brackenwood. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Character Movement
Topic Started: Jul 31 2005, 06:52 PM (999 Views)
Andros
Member Avatar
Check my location.
What script would get a character to move in eight directions with a separate animation for each? If eight is impossible, then four.
Offline Profile Quote Post Goto Top
 
Vector
Member Avatar
Resident Actionscript Guru ♂
Admin
Step 1:
create your movieclip for your player, call it iPlayer.

Step 2:
Make 5 frames (or change to your liking) for walking in each direction, and 5 frames at the very end. The frames need to be in this order (at the moment):
frame placements
 

1-5: Up Left
6-10: Left
11-15: Down Left

16-20: Up Right
21-25: Right
26-30: Down Right

31-35: Up
36-40: Down

41-45: Idle


Step 3:
Put this code on your main frame:
Code:
 

iPlayer.vPhase = 1;
var vSpeed = 10;

iPlayer.stop();

_root.onEnterFrame = function() {

iPlayer.vPhase = (iPlayer.vPhase) < 5 ? iPlayer.vPhase + 1 : 1;

if (Key.isDown(Key.LEFT)) {
 if (Key.isDown(Key.UP)) {
  //Up Left
  iPlayer.gotoAndStop(iPlayer.vPhase);
  iPlayer._x -= vSpeed;
  iPlayer._y -= vSpeed;
 } else if (Key.isDown(Key.DOWN)) {
  //Down Left
  iPlayer.gotoAndStop(iPlayer.vPhase + 10);
  iPlayer._x -= vSpeed;
  iPlayer._y += vSpeed;
 } else {
  //Just plain old left
  iPlayer.gotoAndStop(iPlayer.vPhase + 5);
  iPlayer._x -= vSpeed;
 }
} else if (Key.isDown(Key.RIGHT)) {
 if (Key.isDown(Key.UP)) {
  //Up Right
  iPlayer.gotoAndStop(iPlayer.vPhase + 15);
  iPlayer._x += vSpeed;
  iPlayer._y -= vSpeed;
 } else if (Key.isDown(Key.DOWN)) {
  //Down Right
  iPlayer.gotoAndStop(iPlayer.vPhase + 25);
  iPlayer._x += vSpeed;
  iPlayer._y += vSpeed;
  } else {
  //Just plain old right
  iPlayer.gotoAndStop(iPlayer.vPhase + 20);
  iPlayer._x += vSpeed;
 }
} else if (Key.isDown(Key.UP)) {
 //Just plain old up
  iPlayer.gotoAndStop(iPlayer.vPhase + 30);
  iPlayer._y -= vSpeed;
} else if (Key.isDown(Key.DOWN)) {
 //Just plain old down
  iPlayer.gotoAndStop(iPlayer.vPhase + 35);
  iPlayer._y += vSpeed;
} else {
 //Not doing anything
  iPlayer.gotoAndStop(iPlayer.vPhase + 40);
}
}


Step 4:
It's aliveeeeeeeeeee!!!!!

If you've got any specific questions just hollar! :lol:

<edit>
An alternative would be to have one frame for each direction in the player movieclip, and movieclips within those frames, which lets you have different length cycles. :)
Offline Profile Quote Post Goto Top
 
chluaid
Member Avatar
Bitey's Daddy
Admin
awesome! Now make him jump :P
Offline Profile Quote Post Goto Top
 
Rubberhead
Member Avatar
Fatscat Kittycat
Moderator
Whoa, the script sucks, but damn! That has to be the best animation ever! :blink:
Offline Profile Quote Post Goto Top
 
TheEYE
Member Avatar
Lurys Fey Daemyt
Admin
Rubberhead
Jul 31 2005, 09:07 AM
Whoa, the script sucks, but damn! That has to be the best animation ever!  :blink:

:lol:
I hear that! Vec man, quit wasting your and our time with your crappy AS man... you totally suck you jive turkey! Stick to what you truly excel at... that sweet frame by frame you do man! :P
:bing:
Offline Profile Quote Post Goto Top
 
mayshing
Member Avatar
Brackenwood Newbie
O_o man i would like to see the result of this method.
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
You really should make a game out of that, and draw everything else with that same level of awesomeness! :bfoot:
Offline Profile Quote Post Goto Top
 
Vector
Member Avatar
Resident Actionscript Guru ♂
Admin
O_o

No need for everyone to be so sarcastic... :blink:
Offline Profile Quote Post Goto Top
 
Kalle
Member Avatar
Nemus
We all love you man. :wub:
What the hell would my mySQL database be without you man! ;)
Offline Profile Quote Post Goto Top
 
Andros
Member Avatar
Check my location.
Funny thing is, that animation isn't far off. Has anybody heard of the Kingdom of Loathing? Upon first look, it's reaaaaaaaaallllllly bad, but it in actuality is incredible and delightful. The witty humor and constant random allusions make it one of the better games I've played in a while.

I want to make a Flash-based fan game, so expect many questions in the future.
Offline Profile Quote Post Goto Top
 
boundless
Member Avatar
stuck in the third dimension
I can't get this to work! I made the iPlayer movie clip with 45 keyframes with each set of 5 for the movements. I clicked on the main frame and pasted that code. What did I do wrong?
Offline Profile Quote Post Goto Top
 
mystical-mongoose
Member Avatar
Eggy Toast
How would I change this so that there are only 4 movements and one of them is jumping?
Offline Profile Quote Post Goto Top
 
Vector
Member Avatar
Resident Actionscript Guru ♂
Admin
Here's the source file for this project... have a look, it should help you figure it out a bit more.

Directions Source File

as for your question mongoose, i'll edit this post when i've finished typing :P

<edit>

The following code is for 4 DIRECTIONS ONLY

Code:
 


//Frames 1->5 - Left
//Frames 6->10 - Right
//Frames 11->15 - Up
//Frames 16->20 - Down
//Frames 21->25 - Idle

iPlayer.vPhase = 1;
var vSpeed = 10;

iPlayer.stop();

_root.onEnterFrame = function() {

iPlayer.vPhase = (iPlayer.vPhase) < 5 ? iPlayer.vPhase + 1 : 1;

if (Key.isDown(Key.LEFT)) {
  //Just plain old left
  iPlayer.gotoAndStop(iPlayer.vPhase);
  iPlayer._x -= vSpeed;
       
       } else if (Key.isDown(Key.RIGHT)) {
  //Just plain old right
  iPlayer.gotoAndStop(iPlayer.vPhase + 5);
  iPlayer._x += vSpeed;

} else if (Key.isDown(Key.UP)) {
       //Just plain old up
  iPlayer.gotoAndStop(iPlayer.vPhase + 10);
  iPlayer._y -= vSpeed;

} else if (Key.isDown(Key.DOWN)) {
       //Just plain old down
  iPlayer.gotoAndStop(iPlayer.vPhase + 15);
  iPlayer._y += vSpeed;

} else {
       //Not doing anything
  iPlayer.gotoAndStop(iPlayer.vPhase + 20);
}
}
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
Allrighty vec, I've never seen an increment then start over thingy coded this way...

Quote:
 

iPlayer.vPhase = (iPlayer.vPhase) < 5 ? iPlayer.vPhase + 1 : 1;


Huh? I'm guessing the <5 ? is like an if statment..... and the iPlayer.vPhase+1 is the increment...... and the :1 is what it goes back to??? :blink:
Offline Profile Quote Post Goto Top
 
Vector
Member Avatar
Resident Actionscript Guru ♂
Admin
Yeah this thing is really handy...

variable = (condition) ? (if condition is true) : (if condition = false);

For example,
iPlayer.vPhase = (iPlayer.vPhase) < 5 ? iPlayer.vPhase + 1 : 1;
is saying

if (iPlayer.vPhase) < 5, then set iPlayer.vPhase to iPlayer.vPhase + 1.
Otherwise, set it to 1.
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
oooohhh that's handy. Thanks!
Offline Profile Quote Post Goto Top
 
boundless
Member Avatar
stuck in the third dimension
Is that download for mx 2004? I only have mx :worry:
Offline Profile Quote Post Goto Top
 
Vector
Member Avatar
Resident Actionscript Guru ♂
Admin
Yeah, it is for 2004...

If you want to run this code in MX i think you would need to change
Code:
 
var vSpeed = 10;

to
Code:
 
vSpeed = 10;


That's the only thing I can see off hand...

Here boundless, I saved a FlashMX copy for you :)
Offline Profile Quote Post Goto Top
 
boundless
Member Avatar
stuck in the third dimension
Thanks Vector! :D

Oh I didn't know about that stop(); inside the movieclip. :yfok:
Offline Profile Quote Post Goto Top
 
Andros
Member Avatar
Check my location.
In the long time since I made this topic, the idea has evolved a lot. I've got here what I've accomplished concerning basic quad-directional movement. However, I want to know how to make him jump. I figured that I just needed to copy the code and change the button to SPACE and the location to the animation's frames, but that didn't work. Also, I want to make it so that he can jump while holding UP or DOWN in the corresponding directions. Check here for the swf.

EDIT: Boy, am I stupid. I didn't even NOTICE the topic on the main page called "Character Jump." However, it doesn't help me. How do I establish the ground and gravity? I don't just want a 2D platform either--how would I establish the ground in a way similar to the Simpsons original arcade game and Paper Mario?
Offline Profile Quote Post Goto Top
 
Andros
Member Avatar
Check my location.
Come on! I know I shouldn't bump, but it's been a whole weekend and I haven't been able to continue work on my game.
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
Nuts. Vector took his example down. I so wanted to see it again... :(

Andros - in a game like yours, the ground is wherever you happen to be standing when you begin to jump. If your character is at (300, 200), then store the y location in a variable when they jump. Then reference that variable to see where the ground is, and if your character is touching it. Other than that, it's the same concept as the jump code in the other topic.

I swiped this from the other topic and made a few changes to show you the gist of what I'm saying:

Code:
 
if (Key.isDown(Key.UP) && jumping != true) {
jumping = true;
//stores the characters current position in the variable yGround.
//you later refference this point to see if you are touching the ground.
yGround = this._y;
}
if (jumping == true) {
//if you want to draw a jumping sprite
this.gotoAndStop("jump");
this._y -= jump;
jump -= .5;
if (jump<0) {
 falling = true;
}
if (jump<-15) {
 jump = -15;
}
}
// if you fall below the point you started from, then you are on the ground.
if (this._y<=yGround && falling) {
this._y = yGround;
jump = 12;
jumping = false;
falling = false;
}


That'll only work if you stand in place and jump. If you want to move while you jump, then you'll have to add the x and y distance to both the character in the air, and add the y distance to yGround.
Offline Profile Quote Post Goto Top
 
Andros
Member Avatar
Check my location.
Uh, where would I go about putting that code? It doesn't work on the stage or in the movieclip.
Offline Profile Quote Post Goto Top
 
Andros
Member Avatar
Check my location.
I'm really lost on this one. I'm trying to get as far as I can on this thing with as little help, but I'm truly stumped. I looked through the code you gave me... where does it actually define jumping? It doesn't work. At least now I figured out how to make it give me no errors... anyway... how would I go about defining jumping? Plus, I have no idea how to selectively change the code for midair and on-ground. I've really got a mediocre understanding of Actionscript--I'm used to simple stuff on my graphing calculator. In other words, my knowledge is in conditional statements, variables, setting labels and locations to return to later, etc. If you could maybe help me in a way catered to that, perhaps I'd do better.
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
check your inbox youd receive a message with my info contact me and Ill happily help you ;)
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Actionscript · Next Topic »
Add Reply