PDA

View Full Version : walking character


majik
05-04-2005, 09:05 PM
hi everyone. i'm having problems making my character walk to different sections of the stage. i'v attached a basic flash file, so if anyone can help i'd really appreciate it!!!!! THANKS! :)

Ricod
05-04-2005, 10:41 PM
Welcome to the forums !

It's best to be a bit more specific and descriptive. What do you want exactly ? What is it doing now and what did you try ?

The stuttering in the animation btw is because every frame, you send the animation back to either the 'back' or the 'forward' frame, instead of letting the animation go.

majik
05-05-2005, 10:43 AM
hi, well what i want is for the character to walk to section 1 from the start, if the user presses the right arrow key. then from section 1, if the right arrow key is pressed again, i want the character to walk to section 2. i also need the character to be able to walk back to previous sections depending on if there is one, if the user presses the left arrow key. i have coded it so far to work in this way, but it only works for section 1. i.e. the character starts at the beginning.......if the user presses the right arrow key, it moves to section 1. then from section 1, if the user presses the left arrow key, it walks back to the start.

hope this is more clear.

Ricod
05-05-2005, 12:14 PM
It's because of the limits you set. Instead of using an absolute number as the boundary, you could use a variable instead. As long as your character is before 'lev1', the boundary is set at the _x coordinates of 'lev1'. You could just use the _x coordinates, but if you're looking for something more complicated later, you could use hitTest() to see if your character has reached 'lev1'.

To force your character to stop when it reaches the next level, you could use a listerner to see if the key is being pressed at the moment the next level is reached. Then after the key is released, only then the boundary-variable gets it's new value.

majik
05-05-2005, 01:33 PM
hi, that seems kinda complicated.....i'm new to actionscripting. what i am trying to do seems pretty straightforward, but when it comes to using actionscript for it, it gets complicated.

in simple terms, i want the character to stop at a specific x coordinate. then depending on which key is pressed, it will move to the relevant direction and stop at the section it is heading too. like i said, it works between the start and level 1, but no further. i am trying to work with the hitTest you mentioned, but there must be a simpler way of doing this if it already kind of works? :confused:

Ricod
05-05-2005, 07:13 PM
Like I said, instead of using a set value, use a variable.
You can also use variables to store wether or not your character has reached the _x coordinate where you want to stop the character :
if (_root.mm._x >= _root.boundary) {
_root.level_reached++;
_root.mm.gotoAndStop("idle");
}
//boundary check
if (_root.level_reached == 0) {
_root.boundary = 300;
}else if (_root.level_reached == 1) {
_root.boundary = 450;
}
//walk until
on (keyPress "<Right>") {
this.mm.gotoAndPlay("forward")
_root.mm.go = "right";
}
if (_x < _root.boundary && go == "right") {
_x = _x + 7;
}