# Stop mouse paddle passing over ball?

**URL:** https://forum.kirupa.com/t/stop-mouse-paddle-passing-over-ball/261909
**Category:** programming
**Created:** [June 1, 2008, 5:41pm UTC](https://forum.kirupa.com/t/stop-mouse-paddle-passing-over-ball/261909 "2008-06-01T17:41:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bugi](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bugi](https://forum.kirupa.com/u/bugi)
#### Post date: [June 1, 2008, 5:41pm UTC](https://forum.kirupa.com/t/stop-mouse-paddle-passing-over-ball/261909/1 "2008-06-01T17:41:55Z")

</div>

I’m having problems of the mouse controlled paddle being able to appear on the other side of the ball. The paddle’s Y movement is controlled by the mouse, but the X is animated on mouseclick at a different frame rate than the ball.

I am rewriting to use a “delta” timer so I thought I would put this out there so I have some more ideas when I get back to it.

So the paddle’s y is set by a MouseMove event, the paddle’s x is set by a 15ms timer based on a long switch statement based on the png frames:

```auto
                switch (this.angle)
                {
                    case 0:
                    footX = NaN;
                    break;
                    case 1:
                    footX = -24;
                    break;
                    case 2:
                    footX = -23;
                    break;
                    case 3:
                    footX = -21;

etc.

```

I move the ball like this every 30ms:

```auto
        private function move():void
        {
                ball.x += ball.speedX;
                ball.y += ball.speedY;
        }

```

then check for collisions with the paddles (I think I am going to rewrite this to check row x first then hitTestPoint individual paddles)

```auto
footGlobal = team.men*.localToGlobal(regPoint);
footGlobal.x += table.team1.footX;
ballGlobal = ball.localToGlobal(regPoint);
dx = ballGlobal.x - footGlobal.x;
dy = ballGlobal.y - footGlobal.y;
dist = Math.sqrt(dx * dx + dy * dy);
minDist = ball.radius + 15;
                            
if (dist < minDist)
{
collide(team.men*, footGlobal, dx, dy);

```

I then calculate the angle and bounce it off that side. but if the paddle moves too fast it can pass over without colliding. Could anyone help suggest a more accurate method?

Also, is it bad practice to have objects running at different frame rates?

Thanks

---

<div class="post-metadata">

### Author: ![DangerousDan](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@DangerousDan](https://forum.kirupa.com/u/DangerousDan)
#### Post date: [June 2, 2008, 2:01pm UTC](https://forum.kirupa.com/t/stop-mouse-paddle-passing-over-ball/261909/2 "2008-06-02T14:01:38Z")

</div>

I thought about this when I was writing my own pong game but never really implemented it, anyway my idea was pretty simple.

Once the ball crossed a certain X (a line very close to where the paddle is), you just perform a check on Y of the paddle and ball do all of your hitTesting that way.

```auto

if(ball._x <= paddle._width)
{
   if(ball._y < paddle._y && ball._y > paddle._y-height)
         hit()
 }

```

Something like that, I hope I explained this clearly enough and more importantly I hope this works as I haven’t done any tests yet! :thumb2:
