I´m doing a car game and I need to do some walls, stopping the car taking a short cut accros the circuit. I have been trying to fix this problem using collision detection but I really don’t know how it’s works…
Collision is almost invariably done using ‘hitTest’. It can;
check to see whether the bounding boxes surrounding two movieclips are touching or overlaping.
or
check to see if one coordinate is within the shape of a movieclip.
The second one is best if you don’t want square walls or loads of bounding box hitests.
getting back to your question; create a movieclip which contains all the walls for your track. Give the movieclip an instance name so you can refer to it later. Now add something like this to whatever movieclip your car is. (Replace Mywalls with the instance name you used earlier)
onClipEvent(enterFrame)
{
if(_parent.Mywalls.hitTest(_x,_y,true))
{
//put code that stops car here, maybe reverse x and y movement variables so that the car bounces back off the wall. Beware of corners in walls that are acute angles
}
}
Hitest is rather versitile so I’m sure you can tweak this into something useful.