PDA

View Full Version : how do I make walls? Collision detection?



z_nicz
March 15th, 2004, 04:01 AM
Hey!

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.....:(

How do I create these walls?

// niclas

junahu
March 15th, 2004, 08:47 AM
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.

z_nicz
March 16th, 2004, 07:08 AM
Ok...I got it to work :)

But I got one problem, you see I'm doing this race track...And I want the walls on the race track to be the "hitscan". However, when you create a MC it automaticly becomes a square. The shape inside the movie clip isn't really the boundarys of the MC...

And this doesn't work so well when you're making a circular curve :(

Any suggestions?

Thanks

//niclas

smack_boom
April 25th, 2004, 12:58 AM
i tried this script my guy just ran throught the wall i changed the clips too

zeka
April 25th, 2004, 04:30 AM
niclas can u post ur fla?

LittleFenris
May 22nd, 2004, 04:09 PM
Would hitTest be useful for a platformer game? To keep the player on top of a platform or the floor for example.

dinner dog
May 23rd, 2004, 08:58 AM
hittest is useful for anytime you want to know if something has hit or passed through a point (a platform in a platformer or a wall in a racer).

hitTest is also capable of shapeflag in the form of my_mc.hitTest(x, y, shapeFlag). basicly this is what you want (for both your questions) and I wouldn't mind betting that a search would find you a great source. I would post one but the FAQ says to search. try a search for "RPG art hittest" or something like that and you should be well on your way.

Good luck.

patricktheking
May 26th, 2004, 05:08 PM
Yo how do u make it so if ur car runs over a finish line it goes to the next frame and until it runs over it, you keep racing.....lol