# Collision detection problems

**URL:** <https://forum.kirupa.com/t/collision-detection-problems/2624>\
**Category:** flash\
**Created:** [May 22, 2002, 1:19am UTC](https://forum.kirupa.com/t/collision-detection-problems/2624 "2002-05-22T01:19:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2002, 1:19am UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/1 "2002-05-22T01:19:18Z")

</div>

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?\r\r[www.chickensnack.com](http://www.chickensnack.com)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2002, 2:07am UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/2 "2002-05-22T02:07:17Z")

</div>

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.\r\rI believe it’s\r\rfirstMovieClip.hitTest(secondMovieClip,true);\r\rwhere true is a boolian value which tells the hit test to work on shapes rather than bounding boxes.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2002, 2:36am UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/3 "2002-05-22T02:36:35Z")

</div>

Hmm… that doesn’t seem to work…\rI 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.\rHere’s a simple example:\r ![](http://www.chickensnack.com/example.gif)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2002, 2:58am UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/4 "2002-05-22T02:58:43Z")

</div>

i’m afraid you can only evaluate the shape if you’re hitTesting against a coordinate, it won’t fly with a movie.\r\ryou could use the center point of “you” as the coordinates:

```auto
 \r\rif(_root.police.hitTest(_root.you._x,_root.you._y,true){\r\r ... they got me ...\r\r}else{\r\r ... they missed me ...\r\r}

```

\ror if you’re feeling ambitious, you could write your own hitTest routine. remember the equation for a circle? neither do i. ;)\r\rgood luck!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2002, 3:37am UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/5 "2002-05-22T03:37:01Z")

</div>

ahhhhhh you’re so right… \r\r\<~ slapping head. I was having problems with this eariler… I think that’s why.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2002, 6:22pm UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/6 "2002-05-22T18:22:23Z")

</div>

Thank you so much suprabeener! it works like a charm!\r\r \<embed src=“[http://www.chickensnack.com/flash/gtrc-collision.swf](http://www.chickensnack.com/flash/gtrc-collision.swf)” quality=high pluginspage=“[http://www.macromedia.com/shockwave/download/index.cgi?P1\_Prod\_Version=ShockwaveFlash](http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash)” type=“application/x-shockwave-flash” width=“550” height=“400”\>\r \</embed\>

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2002, 7:02pm UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/7 "2002-05-22T19:02:00Z")

</div>

hey chickensnack… how about displaying your final code, so the rest of us can give it a gander…?\r\rThanks!\r

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 22, 2002, 11:01pm UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/8 "2002-05-22T23:01:09Z")

</div>

Here’s the code (its placed in the actions of “You” not the frame):\r\ronClipEvent (enterFrame) {\r if (\_root.police.hitTest(\_root.you.\_x, \_root.you.\_y, true)) {\r \_root.text = “You’ve been spotted!”;\r } else {\r \_root.text = “You’re OK.”;\r }\r}\r\rThe instance name of the police vision name is “police”.\rYou is “you”, obviously.\rAnd the text field variable is “text”\r\rStill 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.\r\<embed src=“[http://www.chickensnack.com/flash/collision3.swf](http://www.chickensnack.com/flash/collision3.swf)” quality=high pluginspage=“[http://www.macromedia.com/shockwave/download/index.cgi?P1\_Prod\_Version=ShockwaveFlash](http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash)” type=“application/x-shockwave-flash” width=“550” height=“400”\>\r\</embed\>

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 23, 2002, 4:14am UTC](https://forum.kirupa.com/t/collision-detection-problems/2624/9 "2002-05-23T04:14:53Z")

</div>

nice. 🙂
