# Racing game, keeping car in bounderies

**URL:** <https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967>\
**Category:** programming\
**Created:** [July 18, 2004, 5:56pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967 "2004-07-18T17:56:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dangerskew](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dangerskew](https://forum.kirupa.com/u/dangerskew)\
**Post date:** [July 18, 2004, 5:56pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/1 "2004-07-18T17:56:33Z")

</div>

I’m trying to make a racing game, but I don’t know how to keep the car from going off the track. So far I just have it so when you go off the track you’re car’s alpha goes to 50. Does anyone know how I would keep it from going off?

---

<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:** [July 18, 2004, 5:59pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/2 "2004-07-18T17:59:08Z")

</div>

Why can’t ya just have it so you slow down when you go off the boundry thats what most people do amd then its more realistic

---

<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:** [July 18, 2004, 6:12pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/3 "2004-07-18T18:12:15Z")

</div>

Boundary? do you mean walls?

---

<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:** [July 18, 2004, 6:25pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/4 "2004-07-18T18:25:19Z")

</div>

^I meant keeping the car on the track. As for slowing the car down if it’s off the track, how would I do that? I don’t know what to do.

EDIT: Also, I’m just curious as to how I would keep it on the track, as if there were walls around it, that’s kind of what I was trying to do. Make it so you can’t go through the walls.

EDIT: Nevermind, I figured out how to make the car slow down when it’s not touching the track. I still want to know how to make it not go through walls though. Thanks.

---

<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:** [July 18, 2004, 6:39pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/5 "2004-07-18T18:39:54Z")

</div>

you could try:

```php
 
onClipEvent (enterFrame) {
	if (_root.walls.hitTest(getBounds(_root).xMax, _y, true)) {
		this._x -= 5;
	}
	if (_root.walls.hitTest(getBounds(_root).xMin, _y, true)) {
		this._x += 5;
	}
	if (_root.walls.hitTest(_x, getBounds(_root).yMin, true)) {
		this._y += 5;
	}
	if (_root.walls.hitTest(_x, getBounds(_root).yMax, true)) {
	    this._y -= 5;
	}
} 

```

---

<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:** [July 18, 2004, 6:41pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/6 "2004-07-18T18:41:01Z")

</div>

could u save it as MX plz?

---

<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:** [July 18, 2004, 6:49pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/7 "2004-07-18T18:49:53Z")

</div>

I don’t think that one code would work, seeing as how neither the track nor the car are square.

---

<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:** [July 18, 2004, 6:52pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/8 "2004-07-18T18:52:59Z")

</div>

Oh. Well, I couldn’t view the fla so I wouldn’t know.

EDIT: Also, that is the only hitTest code I 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:** [July 18, 2004, 9:31pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/9 "2004-07-18T21:31:46Z")

</div>

here ya go

Changes-  
Added actions to the car (at the very bottom)  
Added a boundarys 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:** [July 18, 2004, 10:03pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/10 "2004-07-18T22:03:51Z")

</div>

Thanks! That works quite well.

---

<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:** [July 18, 2004, 10:13pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/11 "2004-07-18T22:13:25Z")

</div>

your welcome 🙂

---

<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:** [July 24, 2004, 4:38am UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/12 "2004-07-24T04:38:19Z")

</div>

You could check this engine too , it’s working pretty good .  
[http://www.markfennell.com/flash/using.html](http://www.markfennell.com/flash/using.html)

---

<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:** [July 24, 2004, 8:05pm UTC](https://forum.kirupa.com/t/racing-game-keeping-car-in-bounderies/57967/13 "2004-07-24T20:05:36Z")

</div>

That one also has a bug. In that game, when you hit an object, if you keep pressing forward and then turn your car, you can get inside things.
