View Full Version : Character Movement
mbo108
June 3rd, 2004, 11:34 AM
I have been working on a game and I'm trying to get ym character to move a little more efficiently and smoothly. Ideally I want her to move in the way the "beer dude" moves at http://www.daveheinzel.com/beerdude . This is one of my favorite flash games and I have emailed the creator for hints, but so far have heard nothing.
I mean, i can get the character to move with the usual if (Key.isDown(Key.LEFT)){
char_mc._x -= 1; but its jumpy and also the move i use the character, the "bigger" the steps they take. HELP?
-mbo108
signifer123
June 3rd, 2004, 11:51 AM
youcould put smaller steps wbut a higher framefate
mbo108
June 3rd, 2004, 12:12 PM
He still takes bigger and bigger steps each time. I know it is because its adding (or deleting) one each time, but how do i reset it or make it a constant distance he moves...also, i need to make him realistically jump
tommythewolfboy
June 3rd, 2004, 02:00 PM
don't manipulate char_mc._x directly, instead ...
have a speed variable for the character that is updated on key press. You can use an if statement to set a maximum (i.e. only subtract 1 if speed > -3).
The manipulate (onEnterframe) the char_mc._x by adding/subtracting (depending on which way the character is facing - you'll need another variable for this- a boolean, i.e. faceLeft = true) the speed variable from this.
Does that make sense>
mbo108
June 3rd, 2004, 02:55 PM
That sorta makes sense to me, could you flesh it out a little more, maybe write a couple of lines of the code, I'm still a little unclear
tommythewolfboy
June 4th, 2004, 05:00 AM
i'll put something together later for you. What version of flash are you using?
radioxromance
June 4th, 2004, 07:11 PM
i need help with this same thing, please tell us how! heh
thanks
tommythewolfboy
June 8th, 2004, 02:05 PM
OK. I can't post the source at the moment, but the following is what you need to do for some very basic sideways movement on each key press (i.e. no inertia, etc., etc.). Tell me how you get on with this. Please ask any questions if what I'm doing isn't clear or doesn't make sense ... just cutting and pasting a/s code isn't going to teach you anything ... :¬)
Create a new movie with two layers in the main timeline. Name one layer 'as' and another 'clip'. In the clip layer create a simple movie clip and give it the instance name clip_mc in the properties panel. This movie clip should also have two layers - one for the graphic (I had my graphic facing left in frame 1 and right in frame2), and one action script, containing simply stop ();
Then go back to the root timeline and in the 'as' layer paste all of the following:
stop();
// DEFINE MOVEMENT VARIABLES USED BY BUBBLE MOVIECLIP
clipSpd = 0;
clipRight = true;
// MOVEMENT
clip_mc.onEnterFrame = function() {
// MOVE LEFT (S key)
if (Key.isDown(83)) {
// PLAY MOVIECLIP FRAME 1 (i.e. facing left)
this.gotoAndStop(1);
trace('A pressed');
/* ONLY INCREASE SPEED OF MOVEMENT IF CURRENT SPEED IS LESS THAN MAX SPEED
- THIS STOPS THE CLIP'S MOVEMENT GETTING FASTER EVERY TIME YOU PRESS A KEY */
if (_root.clipSpd<1) {
/* NOTE: I'm only adding 1 to clipSpd on each button press, but you can add more if need be - you'll need to change the above line 'if (_root.clipSpd<1)' from '<1' to whatever max speed works for you*/
_root.clipSpd++;
}
// CALCULATE CLIP'S X POSITION BY SUBTRACTING [BECAUSE MOVING LEFT] SPEED
this._x = this._x-_root.clipSpd;
trace(_root.clipSpd);
trace(this._x);
}
// MOVE RIGHT (D key)
if (Key.isDown(68)) {
// PLAY MOVIECLIP FRAME 1 (i.e. facing right)
this.gotoAndStop(2);
trace('S pressed');
/* ONLY INCREASE SPEED OF MOVEMENT IF CURRENT SPEED IS LESS THAN MAX SPEED
- THIS STOPS THE CLIP'S MOVEMENT GETTING FASTER EVERY TIME YOU PRESS A KEY */
if (_root.clipSpd<1) {
_root.clipSpd++;
}
// CALCULATE CLIP'S X POSITION BY ADDING [BECAUSE MOVING RIGHT] SPEED
this._x = this._x+_root.clipSpd;
trace(_root.clipSpd);
trace(this._x);
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.