Discord
Login
Community
DARK THEME

Sprite collision function I made

I made this function you can put into your project to detect sprite collisions. It returns true or false depending on if they are colliding or not. To use it, just make sure both of the sprites are their own objects and have x and y properties. Here is the function:

  checkCol = function(ob1, ob2, colRad)
    colliding = false
    if ob1.x < ob2.x + colRad then
      if ob1.x > ob2.x - colRad then
        if ob1.y < ob2.y + colRad then
          if ob1.y > ob2.y - colRad then
            colliding = true
          end
        end
      end
    end
    
    return colliding
   end

Won't be more simple that:


checkColision = function(obj1, obj2, colRad)
  return (sqrt(pow(obj2.x - obj1.x, 2) + pow(obj2.y - obj1, 2))) < colRad
end

But thanks for making it!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community