Swinging a sword in Xcode with Sprite Kit

| | August 4, 2015

I’m working on making an RPG in Xcode, and I’m having a major gameplay issue when it comes to having my character swing his sword in a way that is realistic and gameplay compatible.

Right now, when the player taps the screen and the sword is in one of the player’s hand, it rotates the upright sword 90 degrees. The sword which is a parent of the player floats in front of the player because of a collision issue

I’m looking for any advice anyone can give on how to add a sword to the game and have it swing in a way that looks somewhat realistic and can damage enemies that are more than a single pixel away from the player

One Response to “Swinging a sword in Xcode with Sprite Kit”

  1. I think most of your problems might be solved by understanding the use of category masks. Simply set the masks to ignore contact and collision between the sword and player categories.

    Specifically, this is done by assigning unsigned integers to the categoryBitMask, collisionBitMask, and contactBitMask properties of the SKPhysicsBody of the SKSpriteNode in question.

    • categoryBitMask is the category of the physics body (e.g. swordCategory)
    • contactBitMask is the product of the ORed categories of the types of nodes you want to test for contact (e.g. enemyCategory | breakableCategory | wallCategory)
    • collisionBitMask is the product of the ORed categories of the types of nodes you want to resolve collision (e.g. enemyCategory | wallCategory)

Leave a Reply