How would I make a clothing system?

Hello. I’m right now in the process of making a character for an action-adventure rpg test game, and I was wondering, how would I go about doing a clothing system?

I’ve drawn some concepts about how the system would work in the eyes of a player, and I do have some ideas as to how I could implement it. But I also have some concerns about some aspects of the system and how it would/should work.

One thing, is weight painting. If I didn’t some faces/vertices to deform, I would weight paint them so that they don’t. But what if I have the chest-plate for example in a different .blend file? What steps would I have to take in order to spawn it in the main game.blend? What would I need to do to make sure it deforms properly and attaches to the right part of the character.

And second thing. I know the soft-body physics are not applicable for full game in the BGE. But does someone have a free cloth-script I could perhaps use? Or some general advice on cloth physics in the BGE?

Sorry 'bout these quiestions, but as you can probably tell, I’m quite a newbie when it comes to actually using a(ny) game engine.
Detailed and informative replies are welcome. Thanks in advance.

  1. The Question is not so n00besque. A n00b would simply trust the Soft Bodies. ;}
  2. I suggest you work with Bones and Constraints. A good Example is that Wormy-Thing that nweissberg has recently offered in his Elpis Thread, to show how easily a Ragdoll can be done. In Fact, your Cloth System should be just a Ragdoll, indeed. ;]

EDIT: This will also work well for Hair, of Course!

Thanks. Although that method for cloth would require for me to set it up manually with every piece of waistcloth and every jacket…
Is an armature required for making a cape? And lots of planes that are parented to their closest corresponding bones? Seems like a lot of work for just one piece of clothing…

Now, I need an answer to the first question. which was, what is the workflow with importing pieces of equipment at runtime from different .blend files, and make it so they spawn at the correct spot and make them attach to the correct spot with the correct weight-painting? If I managed to create hundreds of different clothing and armor pieces, how would I append/link them into the main .blend file of my game?

I want to know about weight paint and many cloth too.

Interesting question, since I ain’t there yet (either), I am interested in how to link different parts (from different scenes/files) in the BGE to other parts as well.

(edit: in the BGE, in realtime / on the fly)

Is there someone who knows how to do this?

You need to use python to get assets from another .blend on the fly, you will be making use of the LibLoad function.

To start, set up the .blend that you will be loading from (clothes.blend for example) so that the clothes are on a non-visible layer such as layer 2. You want to use a non-visible layer because when you use the LibLoad function the .blend that you are loading gets merged into the current scene in you main.blend layer for layer, so that visible layers are visible and non-visible are non-visible.

Once you have that setup, you need to add the code that will add clothes.blend in the right spot. So on your interface where the player chooses what piece of clothing to wear you need something like this:

def wear_clothing():
    remove_clothing()  # Remove any clothing the player is currently wearing

    # Load the clothing into the current scene
    if 'clothes.blend' not in bge.logic.LibList():
        # The .blend hasn't been loaded yet, load it
        bge.logic.LibLoad('clothes.blend', 'Scene')

    # Add the clothing to the scene
    clothing = bge.logic.addObject('clothing', bge.logic.getCurrentController().owner)

    # The object which the clothing will be parented to
    player = bge.logic.getCurrentScene().objects['player']

    # Position the clothing over the player
    clothing.worldPosition = player.worldPosition
    clothing.worldOrientation = player.worldOrientation
    # Parent the clothing to the player

    # Store a reference of the clothing on the player so it can be removed later
    player['clothing'] = clothing

def remove_clothing():
    player = bge.logic.getCurrentScene().objects['player']
    clothing = player.get('clothing')  # Get the clothing that was stored in wear_clothing

    if clothing is not None:
        # The player is wearing clothing, remove it and remove the reference to it
        player['clothing'] = None

Well that answers almost everything, but wouldn’t I want to parent bracers or boots to a bone in the armature? And how would the weight painting in the clothing.blend carry over to the main.blend?

The weight should carry.

As for parenting to specific bones I recommend creating empties and parenting those to the bones and then parenting the boots to the empties. You would do that in the code by just changing the name of the object parenting too, e.g:

# The object which the clothing will be parented to
boot_empty = bge.logic.getCurrentScene().objects['boot_empty']

# Parent the clothing to the player

Thanks for the info, much appreciated.

What do you mean by “weight should carry”? Could you be a bit more specific?

Looks like a solid (proof of concept) solution.

Monster to the rescue! :slight_smile: