# Motion & collision detection threough webcam

**URL:** <https://forum.kirupa.com/t/motion-collision-detection-threough-webcam/265171>\
**Category:** Uncategorized\
**Created:** [July 5, 2008, 8:59am UTC](https://forum.kirupa.com/t/motion-collision-detection-threough-webcam/265171 "2008-07-05T08:59:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadowkeeper](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@shadowkeeper](https://forum.kirupa.com/u/shadowkeeper)\
**Post date:** [July 5, 2008, 8:59am UTC](https://forum.kirupa.com/t/motion-collision-detection-threough-webcam/265171/1 "2008-07-05T08:59:31Z")

</div>

I have a problem regarding the motion and the collision detection through web cam. i have followed the tutorials from the following website [http://www.neuroproductions.be/portf…ebcam\_tutorial](http://www.neuroproductions.be/portfolio/misc/webcam_tutorial) and im not able to understand these lines of code can anyone plz explain me in brief plzz

thanks in advance

```auto

     [LEFT]function hitDetect() {
    var ballX:Number = (ball_mc._x-videoX)/sizeDif;
    var ballY:Number = (ball_mc._y-videoY)/sizeDif;
    now.draw(video_vobj);
    var valNow:Number = (now.getPixel(ballX, ballY) >> 16 & 0xFF);
    var valBefore:Number = (before.getPixel(ballX, ballY) >> 16 & 0xFF);
    if (valNow>valBefore+30 || valNow<valBefore-30) {
        trace("hit");
        if (ball_mc._currentframe == 1) {
            ball_mc.gotoAndPlay(2);
        }
    }
    before.draw(video_vobj);
}[/LEFT]

```
