View Full Version : Collision detection problems
chickensnack
May 21st, 2002, 09:19 PM
Whenever I try do do collision detection it doesn't detect the collision with the shape within the movieclip, but the rectangle border around the movieclip itself... how can I avoid this?
www.chickensnack.com (http://www.chickensnack.com)
upuaut8
May 21st, 2002, 10:07 PM
hit test has some parameters you can set. They take more processor power which is why it's default is set to detect bounding box collision detection rather than shape.
I believe it's
firstMovieClip.hitTest(secondMovieClip,true);
where true is a boolian value which tells the hit test to work on shapes rather than bounding boxes.
chickensnack
May 21st, 2002, 10:36 PM
Hmm... that doesn't seem to work...
I am making a game where you lose if you get spotted by the police (go within their range of sight which is displayed as blue). It would be much better if it could detect the collision with that shape instead of a rectangle.
Here's a simple example:
http://www.chickensnack.com/example.gif
suprabeener
May 21st, 2002, 10:58 PM
i'm afraid you can only evaluate the shape if you're hitTesting against a coordinate, it won't fly with a movie.
you could use the center point of "you" as the coordinates:
if(_root.police.hitTest(_root.you._x,_root.you._y, true){
... they got me ...
}else{
... they missed me ...
}
or if you're feeling ambitious, you could write your own hitTest routine. remember the equation for a circle? neither do i. ;)
good luck!
upuaut8
May 21st, 2002, 11:37 PM
ahhhhhh you're so right..
<~ slapping head. I was having problems with this eariler.. I think that's why.
chickensnack
May 22nd, 2002, 02:22 PM
Thank you so much suprabeener! it works like a charm!
<embed src="http://www.chickensnack.com/flash/gtrc-collision.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="550" height="400">
</embed>
Iammontoya
May 22nd, 2002, 03:02 PM
hey chickensnack.. how about displaying your final code, so the rest of us can give it a gander..?
Thanks!
chickensnack
May 22nd, 2002, 07:01 PM
Here's the code (its placed in the actions of "You" not the frame):
onClipEvent (enterFrame) {
if (_root.police.hitTest(_root.you._x, _root.you._y, true)) {
_root.text = "You've been spotted!";
} else {
_root.text = "You're OK.";
}
}
The instance name of the police vision name is "police".
You is "you", obviously.
And the text field variable is "text"
Still working towards an actual game! I made it so that if you collide with the car itself, it causes the health thing to say you're dead.
<embed src="http://www.chickensnack.com/flash/collision3.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="550" height="400">
</embed>
upuaut8
May 23rd, 2002, 12:14 AM
nice. :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.