jQuery collision plugin | How to actually check if something collided

Chamil

New Member
I'm using jQuery Collision in a simple (or so I thought) game of Pong. There's no AI or online interaction, just two paddles and the ball that one or two players in real life can control.When trying to animate the ball and check if it actually collided with anything, I'm coming up short. I've read the documentation on SourceForge (see above link), but I'm still a bit lost on how to actually check if the collider actually hit anything. The documentation could use a few examples, in my opinion.JavaScript code I currently have:\[code\]$(document).ready(function(){ var ball = $("#ball"); var topPaddle = $("topPaddle"); var bottomPaddle = $("bottomPaddle"); var topPaddleHits = $("#ball").collision("#topPaddle", { mode: "collision", obstacleData: "topOData" }); var bottomPaddleHits = $("#ball").collision("#bottomPaddle", { mode: "collision", obstacleData: "bottomOData" }); var anim = setInterval(function() { ball.css({ "left": "+=5", "top": "+=5" }); if (bottomPaddleHits.data("bottomOData") == bottomPaddle) { anim = clearInterval(anim); alert("Bottom paddle hit!"); } }, 50);});\[/code\]I've also tried \[code\]if (bottomPaddleHits == 1)\[/code\] but that was no good, either.CSS for the top/bottom paddles and the ball, if it matters:\[code\]#ball{ width: 10px; height: 10px; position: absolute; background: #FFF; top: 200px; left: 100px;} #topPaddle{ position: absolute; width: 300px; height: 10px; background: lime; top: 100px; left: 50px;}#bottomPaddle{ position: absolute; width: 300px; height: 10px; background: lime; bottom: 100px; left: 50px;}\[/code\]I'm just not sure how to go about checking if something was actually hit or not.
 
Back
Top