title: Hit Detection Implementation in Processing.JS
body: <p>I am having some trouble with programming hit detection in Processing.JS. I have tried to make a function that checks if something is touching an object and returns true and otherwise returns false. This is that here.   </p>
  
  <p><code>Snake.prototype.checkTouching = function(v){
      if(v.position.x &gt; this.position.x - this.width/2 &amp;&amp; v.position &lt; this.position.x + this.width/2 &amp;&amp; v.position.y &gt; this.positon.y - this.height/2 &amp;&amp; v.position.y &lt; this.position.y + this.height/2){
          return true;
      }else{
          return false;
      }
  };</code><br>
    I am implementing it by creating a new variable "b" in my draw function that holds the value the function returned then using an if statement to check if the value "b" is holding is true. Like so </p>
  
  <pre><code>  var b = snakey.checkTouching(mos);
  var restarts = 0;
  if(b === true){
      restarts += 1;
      Program.restart();
  }   
  </code></pre>
  
  <p>unfortunately even when the object the function is running on is touching the object that is running it nothing happens. I have already checked to see if the logic works and it is valid so I know it has to be my implementation I just can not seem to find out what is wrong with my implementation. Can anyone tell what I am doing wrong? Full program here.<a href="https://www.khanacademy.org/computer-programming/spin-off-of-project-creature-colonies/6085454506295296" rel="nofollow noreferrer">Full Program</a></p>