I'm creating a 2D multiplayer game in javascript, but I'm actually struggling with a problem (not really a problem, but I don't know how to do). I'm actually trying to make my player (circle hitbox) collide with an object that have a rotated square shaped hitbox.

This is the informations that I have :

  • Player positions (x and y)
  • Player hitbox radius (value)
  • Object positions (x and y)
  • Object hitbox width and height (values)
  • Object inclination (in radians)

Can someone help me by explain me how can I do these kind of things ?

  • \$\begingroup\$ Do you want to just detect overlap or get some physical effect? Do rectangular objects have angular velocity? \$\endgroup\$
    – Mangata
    Jun 23, 2022 at 8:34
  • 1
    \$\begingroup\$ There're some previous Q&As about Circle/Square collisions. You can also consider that, by applying the inverse transform of the Square (rotate both the Square and the Circle, but keep their relative distance and direction), you are now working in Square local coordinates, letting you to apply Circle/AABB collision detection methods. \$\endgroup\$
    – liggiorgio
    Jun 23, 2022 at 9:01
  • \$\begingroup\$ @Mangata, the rectangle have a fixed position, and I want the cricle to be replaced outside of then rectangle (so collision response) \$\endgroup\$ Jun 23, 2022 at 9:45
  • \$\begingroup\$ @liggiorgio, yes I already checked, but it's mostly about detection, and some explanations are quite hard to understand for me. \$\endgroup\$ Jun 23, 2022 at 9:46
  • \$\begingroup\$ It sounds to me like you have two questions. 1) How to detect when the circle and rectangle overlap (which the search hits in liggiorgio's explain quite well), and 2) How to resolve the collision you've detected (I have a previous answer here giving an overview of the tactics you might apply for this). Can you review this existing Q&A, and edit your question to walk us through your understanding or attempts based on this research? Highlight a specific step you need help with, so we can focus on that rather than repeat what's already there \$\endgroup\$
    – DMGregory
    Jun 23, 2022 at 16:02


You must log in to answer this question.