# 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