Paul M created a collection of weapons for our character to us, with pickaxes, doubled bladed and single bladed axes as well as a few other objects that could be used for bashing. Also included was three different types of shield. My problem was getting our character to use them.
After a push in the right direction from our constantly helpful lecturer, I discovered mountpoints. These are essentially empty gameobjects where the weapon will instantiate when we need them to. These can be placed all over our character where we need them, but for our current schedule we will be sticking to weapons and shields; the right and left hands.
After some research, I decided to add the empty gameobjects directly in Unity. While this could be done in 3DS Max as well, including doing more complicated things with bones etc, with the Dwarf model not being my own, and time contraints, I didn't want to go messing with it if I could avoid it.
As stated, weapons and shields will then be instantiated at the postion of these mountpoints. A useful feature too is instantiating them at the same rotation of the mountpoints. As each of our weapons will be held in the same way, this is very useful. While initially tedious and needing some trail and error to postion the mountpoint correctly, after plenty of testing, they were working exactly the way we wanted them. Parenting the instantiated weapon then to the mountpoint (done in the code) meant that each weapon would animate along with the character. While all our weapons use a simple chop animation, items like spears could be done in the same way. The spear would go to the mount point, and then the code would point the character to a separate 'thrust' animation. This means that when creating a character, you would be animating only individual actions, not individual animations for every single weapon in a game.
For anyone looking to do something like this, a simple piece of advice is to have all your weapons in your modelling programme at (0,0,0) and at the same rotation.
Once the weapons were coming in at the right place, rotation and animating along with the character, it was a simple matter of making the weapons function, ie, change the code in the player stats so each weapon does different damage. After a brief chat with Petr, who is doing all the actual equipping and GUI code, we decided it would be handier for me to do this, as then we could have all the weapon code in one separate file, with each weapon or shield with its own individual function. Then on Petr's end, it would be a simple matter of calling each function from the weapon code file when it is equipped in the inventory system. Here's an example of one of those functions:
function EquipSingleBladedAxe1 (){
Destroy (mountedWeapon);
var axeSingleBladedInstance : GameObject = Instantiate (axeSingleBladed, weaponMountPoint.transform.position, weaponMountPoint.transform.rotation);
axeSingleBladedInstance.transform.parent = weaponMountPoint;
mountedWeapon = axeSingleBladedInstance;
playerStats.weaponLowRange = 1;
playerStats.weaponHighRange = 6;
}
An important part worth noting is the 'mountedWeapon' variable. This is so the code knows what is currently mounted by the character, so that when he goes to equip a different item, the currently equipped item is removed.
The weapon damage is then in the two range variables at the bottom — in this case, this weapon will do between 1 and 6 damage each hit. This is then added to the character strength giving the final damage output, from which the enemy armour class is deducted giving the actual damage dealt.
The shields work in a similar way, only they affect the armour class stat of the character. While originally we only had the one armour class variable, I split it into various elements while doing this. While for this assignment, we will only have shields, and hence will only need the one armour class variable, in future if we were to add armour, gauntlets etc I thought it would be handier to spilt out each and then bring them together in a forumla.
So for example, if a character had a knight shield (Shield AC 3) plus heavy armour (Torso AC6), adding these together would give a total armour class of 9. Then if the player was to equip the great knight Shield (AC 5), the character's armour would be 11. If we were to have all the armour in just one AC stat, and the add or take away integers from that, it would be too easy to end up with a situation where once you equip something, a permanent or semi-permanent change to the AC stat could be made.
No comments:
Post a Comment