I am struggling with how to implement a melee weapon that can swing when a key is pressed.
I am imagining two different attacks (stab and swing)
I have tried creating two fixtures (character + weapon), two different bodies, two different bodies + revolute joint, but I can not code it to behave the way I imagine it to look like.
STAB:
So with the press of a button, a body/fixture (sensor) would come out for ~1 second and then disappear (alternatively, the body/fixture could always be on the hero and just rotate 90 degrees around the vertices when pressed, and then rotate back to normal)
SWING:
Same thing, but now the weapon will start from the top and swing downwards. Weapon will also be a sensor.
What I have tried:
I created two dynamic bodies.
The weapon has to follow the hero, so I used a revolute joint to hold them together. When a key is pressed, I set the angular velocity of the weapon to a number. However, the weapon will continue to spin after I let go of the key. I tried implementing an if check (if angle is greater than ___, set angular velocity to zero). However, that just means the weapon will stop spinning when I press the key a second time.