Sword Physics Issues

I’ve been musing over the idea of allowing a player to swordfight against other players using their mouse gestures. The swords involved are governed under natural laws of physics, so when 2 swords collide with each other, the swords should bounce and fight against each other in a believable way.

I’ve tried to implement this using ODE and using a control setup where a solid box (the sword) is suspended by 3 “springs”, where its anchors can be moved and rotated using the mouse. The whole setup is something like a marionette.

The only problem with this is that ODE fails miserably at simulating free-floating springs. I’ve tried spongy joints and and my own spring implementation, but no matter what I do, I always end up with a simulation that explodes or with joints that forget where they are connected to the sword.

Should I use a different physics engine, or is there something that I’m doing wrong? I’ve tried angular and velocity damping, but if I move my sword too fast, the sword starts spinning to no abandon.

Any tips would be much appreciated. Thanks!

I don’t know about ODE, but in general when faced with issues like this:

  • Limit the degrees of freedom to a minimum
  • Make sure masses and moments of inertial about all axis are appropriately large enough
  • Add (more) rotational and translational damping, especially proportional to higher powers of velocities.
  • Make sure your simulation is using short enough time steps
  • Carefully choose your integrator (probably not an option with ODE, but I’m sure they have a good one)
  • Make sure you are not mixing objects of too different of scales (large or heavy with light or small)
  • Make sure collision regions are not too thin or sharp

Note: I have pretty much no experience with these kinds of things. I’ve done a bit of developing of my own physics engines, and worked with some mechanical simulators, but done very little works with existing game physics systems. These are just some general solutions to things which tend to make simulated physics get unstable.

Thanks for your reply! I’ve been looking at my simulation more closely, and whenever the sword is rotated to more than 90 degrees from my wanted axis, the sword usually starts exploding. I’m guessing that when that happens, the 3 springs setup an excessively fast oscillation that no matter what damping I apply to it, will continue to accelerate.

So now I’m putting rotational limits on my simulation. Let’s see if this works…