Monday, November 26, 2012

Addon System for Characters

As alpha approached, we needed a system that allowed the programmers to add various objects to the Avatar models. For example, the team wanted me to add a placeholder helmet for the guard characters. This was simply to show we had the capability to do this before the alpha stage was completed, but I decided to go ahead and create the first iteration of the system beyond just adding a hat.

To start, I had to configure the Character Factory class to include this addon system for the guard characters. This was relatively simple to do, and our robust system for adding components seems to be paying off.

My first goal, after that, was to simply create a class that put a box on top of the guards, so I used our dummy avatar class as a template (which is just a big box anyway). From there, I expanded the code to be much more adaptive. When calling the AddModel ability from within Addon component, one has to supply it with the model's location in content, and a Vector3 which is an offset to where the model will be in relation to the character's center.

At this point, the box would now appear wherever I wanted it to be, but I soon realized that my code needed to accommodate multiple objects being attached to a character within the same addon class. I heavily tweaked the containers that held the model's information to be compatible with multiple objects. The Dictionary class proved most useful in keeping tabs on information that was associated to each model (transforms, positions, etc). From there, I simply needed to tweak the Draw method to iterate through every model and draw them.

The final challenge was translating the Vector3 position to be relative the character's position and orientation. Without that, the attached object would quickly become detached once the character started moving. Thus, created a function that takes in the position, and translates each coordinate properly according to the character's orientation.

In the end, I'm quite satisfied with how this worked out. We can now freely add any models, like weapons/armor/clothing, to the characters through my Addons component. Here's a little picture showing a couple of addons being attached (do note, I did this on the Windows version which means I didn't have use of the Avatar models). I attached the little box to all the guards, and added a little shuriken for kicks.


From my testing, both objects move completely in sync with the character, so I'd say this is good progress!

No comments:

Post a Comment