# Odd movement problem

**URL:** <https://forum.kirupa.com/t/odd-movement-problem/118022>\
**Category:** Uncategorized\
**Created:** [August 2, 2004, 3:05am UTC](https://forum.kirupa.com/t/odd-movement-problem/118022 "2004-08-02T03:05:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnyFlash](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@johnnyFlash](https://forum.kirupa.com/u/johnnyFlash)\
**Post date:** [August 2, 2004, 3:05am UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/1 "2004-08-02T03:05:14Z")

</div>

I’ve got this mc that moves left and right when the arrows are pressed, and what i need to do is that once the mc gets to a certain position, it will gotoAndPlay an animation within it.

I tried using hitTest to begin with, but that wasnt working. Am i doing it the easy way of not using hitTest?

Here’s the fla

---

<div class="post-metadata">

**Author:** ![Yeldarb](https://avatars.discourse-cdn.com/v4/letter/y/51bf81/32.png) [@Yeldarb](https://forum.kirupa.com/u/Yeldarb)\
**Post date:** [August 2, 2004, 3:11am UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/2 "2004-08-02T03:11:07Z")

</div>

```auto

onEnterFrame = function() {
if(movieClip._x == theXYouWantToTestHere && movieClip._y == theYYouwantToTestHere) {
movieClip.gotoAndPlay(3820);
}
}

```

Replace movieClip with the instance name of your movieClip, and theXYouWantToTestHere and theYYouWantToTestHere with the X and Y positions of where you want to see if the movieClip is hitting

Put this on the frame of the movie (not the movieClip itself)

---

<div class="post-metadata">

**Author:** ![johnnyFlash](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@johnnyFlash](https://forum.kirupa.com/u/johnnyFlash)\
**Post date:** [August 2, 2004, 3:14am UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/3 "2004-08-02T03:14:23Z")

</div>

thanks for the quick reply :thumb:

I tried out what you suggested, and it looked as if it would work, but, sadly, it didn’t.  
Did you try out the code you just gave me on my fla, and if so, did it work for you?

---

<div class="post-metadata">

**Author:** ![johnnyFlash](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@johnnyFlash](https://forum.kirupa.com/u/johnnyFlash)\
**Post date:** [August 3, 2004, 10:37pm UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/4 "2004-08-03T22:37:08Z")

</div>

Really? no ideas at all?

Pleaes take a look at my fla on the first post, and see what the problem is?

**Thank you**

---

<div class="post-metadata">

**Author:** ![johnnyFlash](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@johnnyFlash](https://forum.kirupa.com/u/johnnyFlash)\
**Post date:** [August 4, 2004, 11:19pm UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/5 "2004-08-04T23:19:45Z")

</div>

i’m getting kind of sad here…☹

I’ guess i’ll ask one more time…if anyone can take a look at my fla and see waht they can do, thanks.

John

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [August 5, 2004, 6:14am UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/6 "2004-08-05T06:14:10Z")

</div>

Put this code in a frame (remove the code on your mc’s)

```auto
var speed = 5;
blob.onEnterFrame = function() {
	if (Key.isDown(Key.RIGHT)) {
		this._x += speed;
		this.gotoAndStop("right");
	}
	if (Key.isDown(Key.LEFT)) {
		this._x -= speed;
		this.gotoAndStop("left");
	}
	if (this.hitTest(tree)) {
		this.gotoAndPlay("anim");
		delete this.onEnterFrame;
	}
};

```

scotty(-:

---

<div class="post-metadata">

**Author:** ![johnnyFlash](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@johnnyFlash](https://forum.kirupa.com/u/johnnyFlash)\
**Post date:** [August 5, 2004, 4:46pm UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/7 "2004-08-05T16:46:12Z")

</div>

hooray!

Thanks for helping me out scotty 🙂  
I was beginning to give up on this thing, heh.

**Thanks again** :thumb:

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [August 5, 2004, 6:23pm UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/8 "2004-08-05T18:23:46Z")

</div>

welcome:thumb:

---

<div class="post-metadata">

**Author:** ![johnnyFlash](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@johnnyFlash](https://forum.kirupa.com/u/johnnyFlash)\
**Post date:** [August 5, 2004, 11:05pm UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/9 "2004-08-05T23:05:02Z")

</div>

Hi again, scotty!

Can you point me in the direction of how to create simple left and right boundries for my blob?

\*\* Thanks \*\*

---

<div class="post-metadata">

**Author:** ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)\
**Post date:** [August 5, 2004, 11:12pm UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/10 "2004-08-05T23:12:45Z")

</div>

```auto

var speed = 5;
blob.onEnterFrame = function() {
if(this._x > 15 && this._x < 150){
	if (Key.isDown(Key.RIGHT)) {
		this._x += speed;
		this.gotoAndStop("right");
	}
	if (Key.isDown(Key.LEFT)) {
		this._x -= speed;
		this.gotoAndStop("left");
	}
	if (this.hitTest(tree)) {
		this.gotoAndPlay("anim");
		delete this.onEnterFrame;
	}
}
}

```

justa suggestion 😉

Prophet.

---

<div class="post-metadata">

**Author:** ![johnnyFlash](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@johnnyFlash](https://forum.kirupa.com/u/johnnyFlash)\
**Post date:** [August 6, 2004, 12:29am UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/11 "2004-08-06T00:29:53Z")

</div>

hm…well with that, the character just stops abruptly at that x value, and can’t be moved again ☹

I’ll keep working on it

---

<div class="post-metadata">

**Author:** ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)\
**Post date:** [August 6, 2004, 6:15pm UTC](https://forum.kirupa.com/t/odd-movement-problem/118022/12 "2004-08-06T18:15:59Z")

</div>

oh yeah… dint think it thru entirely… :S sorry!  
this works…

```auto
var speed = 5;
 var min = -5
 var max=150
 blob.onEnterFrame = function() {
     if(this._x>=max){
         if (Key.isDown(Key.LEFT)) {
             this._x -= speed;
             this.gotoAndStop("left");
         }
     }
     else if(this._x<=min){
         if (Key.isDown(Key.RIGHT)) {
             this._x += speed;
             this.gotoAndStop("right");
         } 
     }
     else{
         if (Key.isDown(Key.RIGHT)) {
             this._x += speed;
             this.gotoAndStop("right");
         } 
         if (Key.isDown(Key.LEFT)) {
             this._x -= speed;
             this.gotoAndStop("left");
         }
     }
     if (this.hitTest(tree)) {
         this.gotoAndPlay("anim");
         delete this.onEnterFrame;
     }
 }

```

or you could use a slightly shorterhand:

```auto
var speed = 5
 var min = -5
 var max=150
 var right = true
 var left = true
 blob.onEnterFrame = function() {
     if(this._x>=max){
         right = false
         left = true
     }
     if(this._x<=min){
         left = false
         right = true
     }
     if(right == true){
         if (Key.isDown(Key.RIGHT)) {
             this._x += speed
             this.gotoAndStop("right")
         } 
     }
     if(left == true){
         if (Key.isDown(Key.LEFT)) {
             this._x -= speed
             this.gotoAndStop("left")
         }
     }
     if (this.hitTest(tree)) {
         this.gotoAndPlay("anim")
         delete this.onEnterFrame
     }
 }

```

or im waiting for someone to swoop in and use an even better method ☹ lol

but i hav an excuse atm - iv got a headache (cue sympathy… or lack of…) lol ciao4now!

Prophet.

EDIT:- btw u thinking of easing that movement or leaving it be?
