- Home /
How do make interchangable objects on a character?
I'm trying to understand how I would go about creating custom objects to place on a character or another object. For example, if I was making a character that could wear different armor, how would I go about making the different pieces of armor connect to the character the correct way each time? Do I create some kind of connection point on the character and on the armor? Would i have to do things differently if I wanted different armor on different types of characters. For example, if I had a human wearing many different hats vs a dog wearing many different hats, could those hats be the same set of hats? Sorry if this is too many questions to ask at once.
Oh buddy, you are not going to like this answer.
You have to 3D model the armor/objects onto the character, all of them, and then disable/enable them as needed. You may be wondering why? Well the fact is that every 3D character has a bone structure, and simply childing objects to the player will not move with the bone structure in any realistic way, your objects need to literally be tied to the bone structure for them to look proper while moving. Now hats are a lot simpler, you can child a hat to the head bone of an entity, but a helmet may require modeling.
I actually love this answer, it helps me out a lot! Would I have to worry about bone structure on things that don't have bones? Like if I wanted to put different kinds of flowers in pots or something like that.
No, not at all, this only applies to objects with bones that are animated. If you want to do something like a plant, you could easily create the Pot for the plan, put an empty GameObject in it you label Anchor or something, and use that to instantiate the plant onto, OR you can put a few different flowers in a Pot and create a script that sets specific ones active, I actually did something very similar to this for a game I'm working on that allows you to customize certain areas. The idea is that all objects exist in the same location, just not at the same time. An example would be.
public class PlantController
{
public GameObject[] plants;
public int current;
void Awake()
{
SetPlant(current);
}
public void SetPlant(int id)
{
for (int i = 0; i < plants.Length; i++)
{
if (i == id)
{
plants[i].SetActive(true);
}
else
{
plants[i].SetActive(false);
}
}
}
}
Also, there's a lot of tutorials on making clothes/armor, the base idea comes down to this: In a 3D program like Blender, you import your character, select the areas which the armor will be, like for a chest piece, you'll select the chest, back, and if it has arms, then the arms as well. Then you duplicate those vertices, and separate them to become a new object, but still linked to the bones, and alter your newly copied vertices. Its actually a lot easier than it sounds, and if you're even remotely decent at 3D modeling, you'll have it figured out in a few hours.
He don't need all of them disabled. He can instantiate them on runtime ins$$anonymous$$d of having n disabled armors. But it's an approach.
While that is true, unless he's making 100's of armors, it's more efficient to have them all loaded at start, since in most cases people swap gear out constantly. Of course, the efficiency is very dependent on the level of detail on the armors. Obviously having 10x 100k vertice chest pieces is not efficient.
Personally, I like to lazy load things, instantiating as needed, but disabling ins$$anonymous$$d of destroying, so that next time I would instantiate it, ins$$anonymous$$d I just enable it.
Of course, let's not forget that unless he's doing Resource.Load(), then all of his armors are already in the RA$$anonymous$$ and instantiation actually takes longer, and requires 2 of the objects to exist now.
Answer by Martin_Gonzalez · Mar 26, 2018 at 07:34 PM
You can create a hat and place it over an empty gameObejct working like a bone in 3d frameworks. So you can set up the gameObject in the place you want (can be the center of the head, the side of it) so the you instanciate the hat in the exact position and rotation of the empty gameObject and place it as the parent of the hat, so if the gameObject is in the player or dog, when the player or dog moves the gameobject will move and the hat too.