Racing game, keeping car in bounderies

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?

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

Boundary? do you mean walls?

^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.

you could try:

 
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;
	}
} 

could u save it as MX plz?

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

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

EDIT: Also, that is the only hitTest code I know.

here ya go

Changes-
Added actions to the car (at the very bottom)
Added a boundarys layer

Thanks! That works quite well.

your welcome :slight_smile:

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

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.