# Trying to stop movement...but cant figure it out

**URL:** https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964
**Category:** Uncategorized
**Created:** [September 11, 2004, 10:49pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964 "2004-09-11T22:49:15Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![saint\_cleve](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@saint\_cleve](https://forum.kirupa.com/u/saint_cleve)
#### Post date: [September 11, 2004, 10:49pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/1 "2004-09-11T22:49:15Z")

</div>

im trying to make a game where your character is moving around the screen…and i want to make it so the character stops in certain areas…like a cliff, i dont want the character to be able to walk over the cliff…i have been searching for actionscripts and whatnot…and i just cant find it…please help…  
flash MX

---

<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: [September 12, 2004, 12:25am UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/2 "2004-09-12T00:25:40Z")

</div>

one method would be to test the position of your character and see if it is over a certain point, for example, say i wanted to make sure that my character wouldn’t go to a point where it’s \_x value is less than 100 and it’s \_x is greater than 200, i could do something like this:

```auto
onClipEvent(enterFrame) {
   if (this._x < 100) {
      this._x = 100;
   } else if (this._x > 200) {
      this._x = 200;
   }
}

```

---

<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: [September 12, 2004, 4:25pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/3 "2004-09-12T16:25:54Z")

</div>

thats almost exactly what i am looking for…but can i make that same effect happen when my player goes ontop of another movie clip?ill post some screen shots

---

<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: [September 12, 2004, 4:34pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/4 "2004-09-12T16:34:47Z")

</div>

this is what the scene looks like…  
 ![](http://img.photobucket.com/albums/v20/bowlingrockspics/full.jpg)

this is the character:  
 ![](http://img.photobucket.com/albums/v20/bowlingrockspics/character.jpg)

this is the ditch that i dont want the character to be able to go over top of:  
 ![](http://img.photobucket.com/albums/v20/bowlingrockspics/ditch.jpg)

this is the actionscript i have for the character so you can move him with the arrow keys:

```auto
onClipEvent (enterFrame) {
	if (Key.isDown(Key.DOWN)) {
		this._y = this._y+10;
		gotoAndStop(2);
	}
	if (Key.isDown(Key.UP)) {
		this._y = this._y-10;
		gotoAndStop(4);
	}
	if (Key.isDown(Key.RIGHT)) {
		this._x = this._x+10;
		gotoAndStop(3);
	}
	if (Key.isDown(Key.LEFT)) {
		this._x = this._x-10;
		gotoAndStop(5);
	}
}
onClipEvent (keyUp) {
	gotoAndStop(1);
}

onClipEvent (enterFrame) {
	if (_root.player, hitTest(_root.holeblock1)) {
		gotoAndStop(1);

	}
}

```

is there an AS that i can use to keep the character from going overtop of the ditch??

---

<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: [September 13, 2004, 8:15am UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/5 "2004-09-13T08:15:58Z")

</div>

do they have to be on the same layer?

---

<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: [September 13, 2004, 12:44pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/6 "2004-09-13T12:44:59Z")

</div>

what about using hitTest()?

---

<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: [September 13, 2004, 5:05pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/7 "2004-09-13T17:05:55Z")

</div>

i dont understand how to make the character stop moving with a hit test

---

<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: [September 13, 2004, 6:22pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/8 "2004-09-13T18:22:00Z")

</div>

you just test to see if the character’s bounding box is intersecting another object’s bounding box.

---

<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: [September 13, 2004, 6:46pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/9 "2004-09-13T18:46:56Z")

</div>

huh :h:

how the heck do i do that???..

sorry…im just not very good at this stuff :puzzle:

---

<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: [September 14, 2004, 3:01am UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/10 "2004-09-14T03:01:59Z")

</div>

if (mcCharacter.hitTest(mcDitch)) {  
//put code to stop the Character now  
trace(“you hit the Ditch and You Cannot move further”);  
}

---

<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: [September 14, 2004, 6:06am UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/11 "2004-09-14T06:06:42Z")

</div>

> [@nishanthe](#):
>
> if (mcCharacter.hitTest(mcDitch)) {  
> //put code to stop the Character now  
> trace(“you hit the Ditch and You Cannot move further”);  
> }

what is the code to stop the character??

i dont want it to say anything…i just want it to stop moving

---

<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: [September 14, 2004, 8:58am UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/12 "2004-09-14T08:58:51Z")

</div>

```auto
onClipEvent (enterFrame) {
    if (canMove) {
	if (Key.isDown(Key.DOWN)) {
                prevY = _y
		this._y = this._y+10;
		gotoAndStop(2);
	}
	if (Key.isDown(Key.UP)) {
                prevY = _y
		this._y = this._y-10;
		gotoAndStop(4);
	}
	if (Key.isDown(Key.RIGHT)) {
                prevX = _x
		this._x = this._x+10;
		gotoAndStop(3);
	}
	if (Key.isDown(Key.LEFT)) {
                prevX = _x
		this._x = this._x-10;
		gotoAndStop(5);
	}
    }
}
onClipEvent (keyUp) {
	gotoAndStop(1);
}

onClipEvent (enterFrame) {
	if (_root.player, hitTest(_root.holeblock1)) {
                _x = prevX;
                _y = prevY;
		gotoAndStop(1);
         }
}

```

possibly a better option here would be to go for the coordinates of the feet, this way his head can go over the cliff, but his feet cannnot - giving the effect that he can walk right upto it.

the way you would do this is:

```auto
 onClipEvent (enterFrame) {
	if (_root.player, hitTest(_root.player._x, _root.player_y, true) {
                _x = prevX;
                _y = prevY;
		gotoAndStop(1);
         }
}

```

hope this helps 🙂

---

<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: [September 14, 2004, 5:01pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/13 "2004-09-14T17:01:25Z")

</div>

now my guy wont even move.

---

<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: [September 14, 2004, 7:27pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/14 "2004-09-14T19:27:42Z")

</div>

i attached a fla of an example of what i want…

MX2004  
if earlier version is needed…just ask…i can add it as MX

---

<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: [September 14, 2004, 11:23pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/15 "2004-09-14T23:23:11Z")

</div>

mx would be useful for me.

---

<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: [September 15, 2004, 12:14am UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/16 "2004-09-15T00:14:44Z")

</div>

ok…here is the MX version…

---

<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: [September 15, 2004, 6:35pm UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/17 "2004-09-15T18:35:23Z")

</div>

after a long day off frantic searching of how to stop a characters movement…i finally came up with a solution.

here is the code that made the character move:

```auto

onClipEvent (enterFrame) {
	if (Key.isDown(Key.DOWN)) {
		this._y = this._y+10;
		gotoAndStop(2);
	}
	if (Key.isDown(Key.UP)) {
		this._y = this._y-10;
		gotoAndStop(3);
	}
	if (Key.isDown(Key.RIGHT)) {
		this._x = this._x+10;
		gotoAndStop(4);
	}
	if (Key.isDown(Key.LEFT)) {
		this._x = this._x-10;
		gotoAndStop(5);
	}
}

```

and here is what i came up with to stop the chracter from moving:

```auto

onClipEvent (enterFrame) {
	if (Key.isDown(Key.DOWN)) {
		this._y = this._y+10;
		gotoAndStop(2);
	}
	if (Key.isDown(Key.UP)) {
		this._y = this._y-10;
		gotoAndStop(3);
	}
	if (Key.isDown(Key.RIGHT)) {
		this._x = this._x+10;
		gotoAndStop(4);
	}
	if (Key.isDown(Key.LEFT)) {
		this._x = this._x-10;
		gotoAndStop(5);
	}
	if (this.hitTest(_root.stopright)){
		this._x = this._x-10;
		gotoAndStop(4);
	}

	if (this.hitTest(_root.stopleft)){
		this._x = this._x-10;
		gotoAndStop(5);
	}

	if (this.hitTest(_root.stopup)){
		this._y = this._y-10;
		gotoAndStop(3);
	}

	if (this.hitTest(_root.stopdown)){
		this._y = this._y+10;
		gotoAndStop(2);
	}
}

```

finally…now…if anyone knows a better way…please let me know

---

<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: [September 25, 2004, 1:55am UTC](https://forum.kirupa.com/t/trying-to-stop-movement-but-cant-figure-it-out/63964/18 "2004-09-25T01:55:10Z")

</div>

i want a MC that has an odd shape to it…everytime i try to get the character to stop on a MC it works, but its always a straight line…i want a more organic shape … i know that it is possible…i have seen it done before…but i cant get anyone to hel me out with it…

PLEASE help me…
