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

Sword Swinging

Topics: User Forum
Jun 27, 2011 at 4:34 AM


I'm trying to create a sword swing using Revolute Joint. Everything works fine except that, of course, it has an effect on the character's body (it makes it jump or move slower, etc.).

For the sword, I create a second rectangle body and made it pass through (returns false on collision) so that it only reports collision and does not collide. I also made it ignore gravity and put some angle limits so that it doesn't rotate where I don't want it.

As far as I can tell, this isn't the best way because as I understand it, the whole point of a joint is to "combine" the two bodies to effect each other but maybe I'm wrong?

Any ideas on what I can do? Perhaps there is a different joint type I can use? or perhaps some other way to do this using Farseer?


Jun 27, 2011 at 1:42 PM

Instead of passing false in the collision event, you can make it a sensor; it won't collide with anything, but will fire the event.

About not effecting the character; you can try to attach the sword to a total different, kinematic body that simply follows your character (just update it's position for instance).

Jun 28, 2011 at 3:22 PM

yea making the sword a sensor is a good idea (and may set the mass to 0 or very low if seting it to sensor doesn't do that)

Jun 28, 2011 at 6:19 PM
Edited Jun 28, 2011 at 6:19 PM

@jordos Good idea, thanks :). I'm using your idea to achieve this effect.

If anyone else has any other ideas, don't be afraid to post here! Thanks again :)

Jun 28, 2011 at 8:32 PM

Well, you might want to consider not making the sword a sensor, but just ignore collision with certain bodies. You can achieve this with collisiongroups. Now you can still let the sword hit other stuff, like dirt particles or something, to create a cool effect.

Jun 29, 2011 at 10:34 AM

Do you need an accurate collision response from the sword hit? If the answer is no, you could consider to cast a Raycast instead of using a body for the sword. Just call a Raycast in the direction the sword is swinging.