This project has moved and is read-only. For the latest updates, please go here.

Revolute Joint + Angle joint crazy issues

Topics: Developer Forum, Project Management Forum, User Forum
May 29, 2011 at 8:33 AM

Okay so I wanted to make a weapon basically that stays attached to the character object so I used a revolute joint. However, I wanted to keep it at certain angles at different times so I made the weapon object have an angle joint with the target angle being the angle I want. So far I got the weapon staying still and following the character , but when I try to swing the weapon by changing the angles joint's target angle it spazzes out and the character model as well as the weapon start spinning like crazy and for some reason fly off randomly. It actually looks pretty funny but very very far from what I want. How do I get the weapon fixture to just change its angle (gradually over a few frames) from one angle to another to simulate a swing without it spazzing?

Also I would prefer if the weapon didn't really push anything around, was sort of translucent but still had collision detection so when it hits enemy objects they take damage. To be more clear, basically the physics for everything acts as if the weapon isn't even there but if an enemy makes contact with it, it still takes damage and has other effects. I tried making it kinematic but this just caused the weapon and character to freeze and do weird stuff.

Please help I don't thinkI can figure this out on my own as its doing things very unexpectedly!

May 29, 2011 at 12:31 PM

Okay I figured out how to solve these problems through hours of trial and error.

1. The kinematic/not have weapon colliding with stuff. I just had OnCollision return false and it basically did everything I wanted perfectly.

2. The angle that I was setting the target to is apparently in radians, so it spiraled out of control because it had to spin ALOT of times to get the crazy values I was giving it (50 degrees, not so big, 50 RADIANS though..). Additionally to get the right angle I had to do: fixture.Body.IgnoreGravity = true; because gravity slightly affected it.

In order to create a swinging effect I had the target angle change back to the starting target angle as soon as it reached the target angle set when you press the slashing button. For example if its in degrees


if (keyState.IsKeyDown(Keys.D))

TargetAngle = 180;//isn't the exact code but for simplicities sake pretend TargetAngle is the targetangle of the weapon's angle joint



if (Math.Abs(TargetAngle)-Math.Abs(


TargetAngle = 0;


Thus every time you press D, the weapon will swing down, then back up.