How do I make a circle hitbox?

I am trying to make a circle hitbox for my enemy sight circle thing but I cant figure it out. My Project2-16-2023_11-30-33.wick also the enemy freaks out when you move.

The “hits” code should have a “CIRCLE” mode. I don’t use it often, and when I’m trying it now it’s not really working, so I’m not sure if I can explain how to make it work-
but there’s another way…

Using the pythagorean theorem, you can tell the distance between the player and the circle.
If the distance is less than the sum of the radius of both objects, then they’re touching, otherwise, they’re not.

With this concept, you can create this function in a default script:

window.circleHits=function(obj1,obj2){
return Math.sqrt(Math.pow(obj1.x-obj2.x,2)+Math.pow(obj1.y-obj2.y,2))<(obj1.width/2)+(obj2.width/2)
}

And then, whenever you want to check if two circles are hitting, just type “circleHits(this,p)” rather than “this.hits(p)

I made these changes to the file you shared: file.wick (10.6 KB)

thanks this helps a lot. now there’s just a problem with the enemy freaking out.

1 Like