Search code examples
javalibgdxcollision-detection

Whats the best way to do attack collision in libGDX/Box2D?


I'm trying to make rogue-like game. Now i'm using Box2D to detect collisions with enemies (so i can destroy them when i collide with them), but i don't have any idea how to handle player's attack. I need to attack outside of my box2D player's body, i tried to create sensor's bodies when i'm attacking, but it didnt work for me (

Any suggestions about it ?

p.s sorry for my Indiano english ;D


Solution

  • You can either add/remove Sensor fixtures every time you attack or use Ray-Casting. I use both, depending on the dynamics of the attack (a dagger stab for example could be as simple as one ray-cast ray). I did quite a lot of research on this since I thought it would be ti heavy to add/remove things every time an attack occurs but there is no other feasible way with Box2D.