# Movement

**URL:** <https://forum.kirupa.com/t/movement/102172>\
**Category:** Uncategorized\
**Created:** [February 20, 2004, 3:02pm UTC](https://forum.kirupa.com/t/movement/102172 "2004-02-20T15:02:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ANIMAL](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ANIMAL](https://forum.kirupa.com/u/ANIMAL)\
**Post date:** [February 20, 2004, 3:02pm UTC](https://forum.kirupa.com/t/movement/102172/1 "2004-02-20T15:02:59Z")

</div>

Hi, 😃

I am trying to make a little game however at the moment i have been trying to figure out how to make my charector when idle show movieclip 1 in its place and when the left and right arrows are being pressed show movie clip 2 and for the charector to move left or right at a speed of 5 depending on what key is being pressed.

Summary:  
no keys pressed - Charector idle, movie clip 1 shown on screen  
Left key pressed - charector moves left at speed of 5  
Right key pressed - Charectot moves right at a speed of 5

How do i do this???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 20, 2004, 3:15pm UTC](https://forum.kirupa.com/t/movement/102172/2 "2004-02-20T15:15:57Z")

</div>

here is an example…  
the char is 3 key frames, with lables idle, left and right…  
just look at it, it’s pretty simple for basic movement…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 20, 2004, 3:25pm UTC](https://forum.kirupa.com/t/movement/102172/3 "2004-02-20T15:25:14Z")

</div>

I can’t seem to get my else bits right ☹  
(yes the code below is mostly borrowed from movement-keys.fla aswell :D)

After walk right i want it to go to else “idle right” and after left “idle left”

where do i place  
[AS] else {  
this.gotoAndStop(“idle right”);  
}[/AS]  
and  
[AS] else {  
this.gotoAndStop(“idle left”);  
}[/AS]

[AS]  
onClipEvent (load) {  
// declare and set speed variable  
speed = 5;  
}  
onClipEvent (enterFrame) {  
// move left, or right  
if (Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT)) {  
\_x -= speed;  
this.gotoAndPlay(“walk left”);  
}  
if (Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT)) {  
\_x += speed;  
this.gotoAndPlay(“walk right”);  
}  
//  
// move diagonally  
if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.DOWN)) {  
}  
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.DOWN)) {  
}  
if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP)) {  
}  
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.UP)) {  
}  
//  
// loop to opposite side of the masked area when the beetle travels off-screen  
if (\_y\<0) {  
\_y = 60;  
}  
if (\_y\>60) {  
\_y = 0;  
}  
if (\_x\<0) {  
\_x = 300;  
}  
if (\_x\>300) {  
\_x = 0;  
}  
//  
// maintain position and rotation of beetle shadow  
with (\_root.shadow) {  
\_x = this.\_x+3;  
\_y = this.\_y+3;  
\_rotation = this.\_rotation+90;  
}  
}

[/AS]

ps i know half of the code there i don’t need for what i am doing but i may find a use for it so i kept it there 🙂

Thank You for the help 😃
