# Stop Car

**URL:** <https://forum.kirupa.com/t/stop-car/10358>\
**Category:** flash\
**Created:** [December 30, 2002, 11:38am UTC](https://forum.kirupa.com/t/stop-car/10358 "2002-12-30T11:38:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![luster](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@luster](https://forum.kirupa.com/u/luster)\
**Post date:** [December 30, 2002, 11:38am UTC](https://forum.kirupa.com/t/stop-car/10358/1 "2002-12-30T11:38:32Z")

</div>

Hi,

I made,following one of the tutorials, a car that moves using keys like Up,Down,Left,Right.

Now i wonder how to do it that you draw a layer “wall” and if the car drives, it cannot pass it, it has to go around.(Like a maze)  
I think this has maybe something to do with collision detection.

Please reply!!!

---

<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:** [December 30, 2002, 12:47pm UTC](https://forum.kirupa.com/t/stop-car/10358/2 "2002-12-30T12:47:52Z")

</div>

on my game i just used hitTest() function… i guess you could’ve also limited that but getting the x and y coordinates and comparing them to the wall’s coordinates… for a maze, i dont think the latter method would work efficiently, i guess you’d have to use hitTest()

cheers  
:A+: ![](http://www.flashdevils.com/~ahmed/hmed.gif)

---

<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:** [December 30, 2002, 1:31pm UTC](https://forum.kirupa.com/t/stop-car/10358/3 "2002-12-30T13:31:49Z")

</div>

you will have to create a movie clip with an instance name like “ **wall** ” and use a script similar to that:

```auto
if (wall.hitTest(getBounds(_root).xMax, _y, true)) {
	speed = 0;
}
if (wall.hitTest(getBounds(_root).xMin, _y, true)) {
	speed = 0;
}
if (wall.hitTest(_x, getBounds(_root).yMax, true)) {
	speed = 0;
}
if (wall.hitTest(_x, getBounds(_root).yMin, true)) {
	speed = 0;
}

```

=)

---

<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:** [December 31, 2002, 5:39am UTC](https://forum.kirupa.com/t/stop-car/10358/4 "2002-12-31T05:39:59Z")

</div>

Interesting line of code guigo… With the getbounds…

Will that test every x pixel for the bounds of the car with that… or just the maxX pixel?

UGHH… Nevemrind… I’m stupid I’m editting this after previewing it again…

_hits himself with a giant salami_

---

<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:** [December 31, 2002, 5:32pm UTC](https://forum.kirupa.com/t/stop-car/10358/5 "2002-12-31T17:32:15Z")

</div>

[SIZE=1]::I feel some code-explaining needed::[/SIZE]

---

<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:** [January 1, 2003, 12:13am UTC](https://forum.kirupa.com/t/stop-car/10358/6 "2003-01-01T00:13:39Z")

</div>

Not to hard to explain.

Its saying if the wall got hi by anything moving trace the bounds witch is tghe lines out side the object and make it stop.

---

<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:** [January 1, 2003, 4:37pm UTC](https://forum.kirupa.com/t/stop-car/10358/7 "2003-01-01T16:37:40Z")

</div>

I tried the code for a time ,but it doesn’t work.  
When i move the car, the wall moves with it!

Thanks, but please help

---

<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:** [January 1, 2003, 5:29pm UTC](https://forum.kirupa.com/t/stop-car/10358/8 "2003-01-01T17:29:11Z")

</div>

Luster do you have AIM.MSN If you do what is it.

Well i made a car game example a while ago and here is the link to the post.  
[http://www.kirupaforum.com/showthread.php?s=&threadid=11576&highlight=Car+example](http://www.kirupaforum.com/showthread.php?s=&threadid=11576&highlight=Car+example)

---

<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:** [January 2, 2003, 11:48am UTC](https://forum.kirupa.com/t/stop-car/10358/9 "2003-01-02T11:48:04Z")

</div>

my computer is on repair.

That piece of code must be placed on an **enterframe** handler, and, yes BullDog, it does exactly what you said.

I´m fixing some fla for you guys, jus give me a min or two:)
