View Full Version : hit Testing movie clips.
amedrano_bi
January 2nd, 2008, 04:05 PM
How can you hit test a movieClip that isnt just a big square?
There is a sample drawing attached.
-a:sc:
ArmoredSandwich
January 2nd, 2008, 07:26 PM
How can you hit test a movieClip that isnt just a big square?
There is a sample drawing attached.
-a:sc:
tileBased:
http://www.tonypa.pri.ee/tbw/tut24.html
http://oos.moxiecode.com/tut_11/index.html
And there was a whole other way you could do something like that but unfortunately I lost the link to that page :S
Basically you should split up you line into small areas like this.
http://www.wonima.demon.nl/other/hittestLines.JPG
The link had an algorithm that could do something like that. Maybe someone else has it.
This was mainly used to check if a bullet or something hits something. But I guess you could use it for something like this.
Because you ask this question I do not think you know really how hittesting is working. If you realized that, youd know how difficult it is to achieve something you want. Try to look up what hittest really is.
Mr beef
January 2nd, 2008, 07:36 PM
Didnt check the links but what about shapeflag hitTest? it isnt too good but it doesnt check the bounding box, but the entire shape.
if(mc1.hitTest(_mc2._x,mc2._y,shapeflag)){
Something like that. I use it, well at least for now, because its easier for what I want. Second way was using classes and vectors but classes hate me for now :)
But the above is probably alot more accurate and reliable. Depends on your knowledge of AS and how serious a project is.
skimmmer
January 2nd, 2008, 10:38 PM
For something in the picture you submitted I would use this:
if (Key.isDown(Key.Right)) {
for (r=-10; r<10; r++) {
if (ground.hitTest(car._x, (car._y+r), true)) {
step = r;
}
}
car._x += 2;
car._y += step;
}
if (Key.isDown(Key.Left)) {
for (r=-10; r<10; r++) {
if (ground.hitTest(car._x, (car._y+r), true)) {
step = r;
}
}
car._x -= 2;
car._y += step;
}
This just checks if each point touches and then when it doesn't it will move up by that step.
amedrano_bi
January 3rd, 2008, 10:47 AM
Hey thanks guys!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.