afxWeapon Design Blog #2: Fire Sword
by Michael Perry · 06/20/2007 (7:02 am) · 17 comments
[Oh GG web-deities, please do not smite me for double blogging]
Greetings, again, all! I really wanted to separate the announcement and tech behind afxWeapon from the actual design and implementation of a specific effect: Fire Sword. To see the full code of this effect, head over to the afxWeapon Resource, download the files, and open up afxWeapons.cs.
Once the afxWeapon resource is integrated into your code, it's safe to say you have 4 major steps to go through to reach a final result:
Step One: Design:
I love the concept of a fire or flame sword. In an RPG, or life, it's hard to beat the damage done by the blunt trauma of a swung weapon, the slice damage of the edge, and the after effect of flaming goodness =).
Designing a sword that appears to be on fire was not difficult. To give my Fire Sword a little quirk, I decided on 5 fire orbs that swirl around the tip of the sword, as opposed to the whole sword being on fire. Also, since this was the first afxWeapon test, I wanted to develop using assets and effects already available to me. Great Ball of Fire to the rescue! GBoF is a very impressive spell found in the Arcane.FX Demo. I was able to follow the spell's pattern to create my Fire Sword.
Figure 1: Great Ball of Fire Spell

Step Two: Modeling the weapon
With the very powerful AFX constraint system being a key component in afxWeapon, some model adjustments for the sword needed to be made.
I used the broadsword from Tridinaut's Medieval Weapon Pack. Using Maya, I opened up the broadsword.obj, and lucky for me, it was completely raw (no Torque hierarchy or nodes or nothin'). This gave me the freedom to set it up specifically for my system.
After the usual set up of Torque hierarchy and proper scaling, I had the sword visually where I wanted it. Based on some hints for AFX Spell Design Blog #2: Fire Tower, I set up three major components on the weapon.
First, I moved the bounding box up so that the bottom of the box was in the middle of the sword handle. This basically tells Torque that the origin of the sword is in the center of the handle, which in the end determines where the sword gets mounted on the player. Next, I placed two mountpoints on the sword. One was placed in the middle of the blade, and the other placed at the tip of the sword. I named these nodes bladeMiddle and swordtip, respectively. With the help of maya2dts, I exported the model and tested it in Show Tool and Weapon Crafter to make sure everything was fine:
Figure 2: Maya Representation of Sword
*Note* - Notice where the bounding box is located, and the green point on the sword tip is the "swordpoint" node.
Step Three: Effects List and Creation:
Based on the design, I had 3 major effects to implement: the actual sword representation, swirling fire orbs, and an equip effect. Any AFX effect can be added to an afxWeapon. If you wanted a permanent zodiac under the player while he's wielding a particular weapon, you are free to do so. For my effect, I wanted something simple to happen when the player equipped the sword. I also wanted a permanent effect while he held on to it.
Before we get into the pretty effects, I'll cover the core aspects of the actual weapon, and how I got it in using AFX. Keep in mind, that when making an AFX effect, you first create a component or modifier, then you WRAP it up.
Normally, when you want a weapon in the world, you have to make an Item datablock. To equip the item to the Player properly, you then have to make a ShapeBaseImage datablock. In AFX, it's so much simpler and cleaner.
The component effect is the afxModelData, in which I specified two fields: the shape file and a flag specifying the sequence of the model to animate with whatever it mounts to. Every field in the wrapper (BroadSword_EW) is crucial. The specified effect is the modelData. To get the mounting effect, I specified the constraint as "wielder.Mount0", which is an existing mount point on Kork.
The string, "wielder", is very, VERY, important to the afxWeapon system. The class internally notes (in C++) that the wielder is the person who calls the method, equipWeapon(). If you use "caster" or "player", the weapon will not mount properly, and the effects won't display.
Two important fields I learned about while first scripting this weapon allow you to specify an effect as a constraint:
Without this code, the weapon you see mounted to the Kork is the equivalent of a hologram. The fire orbs will not know where to swirl without these fields being specified.
Figure 3: Broadsword Effect

I decided on a shock wave effect to appear when the fire orbs combusted. An afxZodiac works perfectly for showing effects on terrains, so I followed the GBoF example and created a zodiac that grows over time, using the weapon wielder as the starting point.
The component effect was the actual afxZodiacData, which contained the texture, radius, rate of growth, and rotation rate.
The effect wrapper needed to know what effect to display and where to start, so I specified the new zodiac and for the constraint I chose "wielder."
For the rest of the shockwave, specifying a fade time and lifetime gives it a smooth transition out of the scene, plus it looks darn realistic =)
Figure 4: Shockwave

The last effect is the swirling ring of fire made of 5 flame orbs. This effect is more or less ripped straight from GBoF. I made three major changes to get the desired path and appearance of the fire:
Finally, we see the reason for giving the BroadSword effect a name, specifying it as a constraint source, and putting a "swordtip" node in the actual model before exporting.
posConstraint specifies the effect (or object) the fireOrb should constrain ("mount") to. #effect specifies that we are looking for an effect, BroadSword is the effect, and swordtip is a specific point on the effect we constrain to.
I discovered orientConstraint as a result of a graphical "bug" in my ring of fire. Without orientConstraint, my effect looked like this:
Figure 5: Ring of Fire facing wrong direction

After specifying the orientConstraint, the ring of fire always faced the direction of the swordtip node.
Figure 6: Correct Ring of Fire orientation

The last part was building the afxWeaponData. The model, shockwave, and fire orbs were dropped in using the addEffect field.
The rest of the fields in the afxFireSword datablock were the actual RPG elments, such as damage, range, skill, and so on.
Step 4: Implementation and Testing
To display an afxWeapon effect, a Player object must call the ConsoleMethod equipWeapon(afxWeaponData).
I really hate typing in the console, especially when I have to repeat a process often during debugging and experimentation. So, I created an ItemData datablock and set it's pickUpName to the name of my afxWeaponData datablock: "afxFireSword".
The onCollision function for the new ItemData calls the equipWeapon function for me, using its pickUpName to let the Player know which datablock to use. All done!
Well, I hope my first effect design blog was helpful for those planning on using afxWeapon, or any AFX module. You can now see why I made the blogs separate. Have a look through the resource, and let me know if you have any questions.
I am also going on the record and saying that Arcane FX is the most awesome Torque Tech to be released since the actual game engine itself! Developing for it is just as fun as playing with the final results.
More to come....next up, Thor's Hammer as an actual afxWeapon. =)
Greetings, again, all! I really wanted to separate the announcement and tech behind afxWeapon from the actual design and implementation of a specific effect: Fire Sword. To see the full code of this effect, head over to the afxWeapon Resource, download the files, and open up afxWeapons.cs.
Once the afxWeapon resource is integrated into your code, it's safe to say you have 4 major steps to go through to reach a final result:
Step One: Design:
I love the concept of a fire or flame sword. In an RPG, or life, it's hard to beat the damage done by the blunt trauma of a swung weapon, the slice damage of the edge, and the after effect of flaming goodness =).
Designing a sword that appears to be on fire was not difficult. To give my Fire Sword a little quirk, I decided on 5 fire orbs that swirl around the tip of the sword, as opposed to the whole sword being on fire. Also, since this was the first afxWeapon test, I wanted to develop using assets and effects already available to me. Great Ball of Fire to the rescue! GBoF is a very impressive spell found in the Arcane.FX Demo. I was able to follow the spell's pattern to create my Fire Sword.
Figure 1: Great Ball of Fire Spell

Step Two: Modeling the weapon
With the very powerful AFX constraint system being a key component in afxWeapon, some model adjustments for the sword needed to be made.
I used the broadsword from Tridinaut's Medieval Weapon Pack. Using Maya, I opened up the broadsword.obj, and lucky for me, it was completely raw (no Torque hierarchy or nodes or nothin'). This gave me the freedom to set it up specifically for my system.
After the usual set up of Torque hierarchy and proper scaling, I had the sword visually where I wanted it. Based on some hints for AFX Spell Design Blog #2: Fire Tower, I set up three major components on the weapon.
First, I moved the bounding box up so that the bottom of the box was in the middle of the sword handle. This basically tells Torque that the origin of the sword is in the center of the handle, which in the end determines where the sword gets mounted on the player. Next, I placed two mountpoints on the sword. One was placed in the middle of the blade, and the other placed at the tip of the sword. I named these nodes bladeMiddle and swordtip, respectively. With the help of maya2dts, I exported the model and tested it in Show Tool and Weapon Crafter to make sure everything was fine:
Figure 2: Maya Representation of Sword
*Note* - Notice where the bounding box is located, and the green point on the sword tip is the "swordpoint" node.Step Three: Effects List and Creation:
Based on the design, I had 3 major effects to implement: the actual sword representation, swirling fire orbs, and an equip effect. Any AFX effect can be added to an afxWeapon. If you wanted a permanent zodiac under the player while he's wielding a particular weapon, you are free to do so. For my effect, I wanted something simple to happen when the player equipped the sword. I also wanted a permanent effect while he held on to it.
Before we get into the pretty effects, I'll cover the core aspects of the actual weapon, and how I got it in using AFX. Keep in mind, that when making an AFX effect, you first create a component or modifier, then you WRAP it up.
Normally, when you want a weapon in the world, you have to make an Item datablock. To equip the item to the Player properly, you then have to make a ShapeBaseImage datablock. In AFX, it's so much simpler and cleaner.
The component effect is the afxModelData, in which I specified two fields: the shape file and a flag specifying the sequence of the model to animate with whatever it mounts to. Every field in the wrapper (BroadSword_EW) is crucial. The specified effect is the modelData. To get the mounting effect, I specified the constraint as "wielder.Mount0", which is an existing mount point on Kork.
The string, "wielder", is very, VERY, important to the afxWeapon system. The class internally notes (in C++) that the wielder is the person who calls the method, equipWeapon(). If you use "caster" or "player", the weapon will not mount properly, and the effects won't display.
Two important fields I learned about while first scripting this weapon allow you to specify an effect as a constraint:
...
effectName = "BroadSword"; // Give the effect an internal name
isConstraintSrc = true; // Turn this effect into a contraint source
// to allow mounting of other effects
...Without this code, the weapon you see mounted to the Kork is the equivalent of a hologram. The fire orbs will not know where to swirl without these fields being specified.
Figure 3: Broadsword Effect

I decided on a shock wave effect to appear when the fire orbs combusted. An afxZodiac works perfectly for showing effects on terrains, so I followed the GBoF example and created a zodiac that grows over time, using the weapon wielder as the starting point.
The component effect was the actual afxZodiacData, which contained the texture, radius, rate of growth, and rotation rate.
The effect wrapper needed to know what effect to display and where to start, so I specified the new zodiac and for the constraint I chose "wielder."
datablock afxEffectWrapperData(FireSword_EquipShockwave_EW)
{
effect = FireSword_EquipShockwave_CE;
posConstraint = "wielder";
....
};For the rest of the shockwave, specifying a fade time and lifetime gives it a smooth transition out of the scene, plus it looks darn realistic =)
Figure 4: Shockwave

The last effect is the swirling ring of fire made of 5 flame orbs. This effect is more or less ripped straight from GBoF. I made three major changes to get the desired path and appearance of the fire:
- The spinData used to modify the fire orbs had an increased spinRate[li]I changed the axis on which the orbs are offset and rotate[li]I changed the constraint of each fire orb wrapper
[b]// In each FireSword_FireOrb effectWrapper[/b] ... posConstraint = "#effect.BroadSword.swordtip"; orientConstraint = "#effect.BroadSword.swordtip"; ...
Finally, we see the reason for giving the BroadSword effect a name, specifying it as a constraint source, and putting a "swordtip" node in the actual model before exporting.
posConstraint specifies the effect (or object) the fireOrb should constrain ("mount") to. #effect specifies that we are looking for an effect, BroadSword is the effect, and swordtip is a specific point on the effect we constrain to.
I discovered orientConstraint as a result of a graphical "bug" in my ring of fire. Without orientConstraint, my effect looked like this:
Figure 5: Ring of Fire facing wrong direction

After specifying the orientConstraint, the ring of fire always faced the direction of the swordtip node.
Figure 6: Correct Ring of Fire orientation

The last part was building the afxWeaponData. The model, shockwave, and fire orbs were dropped in using the addEffect field.
The rest of the fields in the afxFireSword datablock were the actual RPG elments, such as damage, range, skill, and so on.
Step 4: Implementation and Testing
To display an afxWeapon effect, a Player object must call the ConsoleMethod equipWeapon(afxWeaponData).
I really hate typing in the console, especially when I have to repeat a process often during debugging and experimentation. So, I created an ItemData datablock and set it's pickUpName to the name of my afxWeaponData datablock: "afxFireSword".
The onCollision function for the new ItemData calls the equipWeapon function for me, using its pickUpName to let the Player know which datablock to use. All done!
Well, I hope my first effect design blog was helpful for those planning on using afxWeapon, or any AFX module. You can now see why I made the blogs separate. Have a look through the resource, and let me know if you have any questions.
I am also going on the record and saying that Arcane FX is the most awesome Torque Tech to be released since the actual game engine itself! Developing for it is just as fun as playing with the final results.
More to come....next up, Thor's Hammer as an actual afxWeapon. =)
#2
With the origin being in the center of the handle, I didn't need to make another mountpoint, so that's one less node to create and export and reference as a constraint point.
Plus, I didn't have to write any extra code for the mounting...I just had to give the object to mount to "wielder" and his mountpoint "mount0".
Boom, done.
06/20/2007 (8:07 am)
Honestly, my original reason is because that's what Matt Durante said in his blog post (AFX Fire Tower #2). I was curious to see if it really worked in my code, and sure enough, it did. With the origin being in the center of the handle, I didn't need to make another mountpoint, so that's one less node to create and export and reference as a constraint point.
Plus, I didn't have to write any extra code for the mounting...I just had to give the object to mount to "wielder" and his mountpoint "mount0".
Boom, done.
#3
06/20/2007 (8:20 am)
Something the AFX constraint system currently lacks is a way to specify a node-to-node mounting. One can specify an arbitrary node on the mounting object (player) as the mount location but not an arbitrary node on the mounted object (sword) for where the attachment is made. There are ways around the limitation, but specifying a node-to-node mounting would be very convenient.
#4
06/20/2007 (12:38 pm)
So, just wondering...do afxWeapons retain their collision meshes after they are mounted?
#5
AFX Devs will want to weigh in on this.
06/20/2007 (12:57 pm)
Hmm....as far as I know, they act like mounted images/shapes....so they will pass through objects as if they are still "holograms."AFX Devs will want to weigh in on this.
#6
06/20/2007 (1:14 pm)
@ Rubes -- Are you thinking client-side or server-side collisions?
#7
06/20/2007 (1:23 pm)
Client-side, I believe. I'd like for players to be able to click on other player's/NPC's weapons to select them. Mounted images don't work since they have no collision meshes, but mounted StaticShapes don't animate properly.
#8
06/20/2007 (2:14 pm)
Hmm... 3 blogs in a row touting AFX. I may have to invest in this wonder:)
#9
06/20/2007 (2:38 pm)
@ Rubes -- I'll run some tests and report back.
#10
On the other hand, it looks like enhancing afxModel to do this will not be complicated so I'm looking into it. If the changes are straight-forward, I'll post them in the private AFX forums.
06/20/2007 (5:42 pm)
@ Rubes -- I thought afxModel (a light-weight client-only model effect which Michael uses for the sword) might work, but on closer look, they currently lack some of the code required for castRay intersections. afxModels currently inherit from GameBase rather than ShapeBase (hence the light-weight aspect), but ShapeBase is where the collision handling is done.On the other hand, it looks like enhancing afxModel to do this will not be complicated so I'm looking into it. If the changes are straight-forward, I'll post them in the private AFX forums.
#11
06/20/2007 (5:49 pm)
@Jeff - Cool to hear. I'll update my afxWeapon as need be if you enhance the afxModel. I can post a follow up resource or upgrade my current one with some sample combat systems afterwards.
#12
06/21/2007 (3:30 pm)
@ Rubes -- I made a few changes to the afxModel code and they can now be recognized by the selection system. With these, if you use afxModel effects to mount weapons to Players and NPCs, you can make them selectable by other players. Changes are posted in the private AFX forums.
#13

More Pics:
www.zombieshortbus.com/ggtutorials/screenshot_001-00001.png
www.zombieshortbus.com/ggtutorials/screenshot_001-00002.png
www.zombieshortbus.com/ggtutorials/screenshot_001-00003.png
www.zombieshortbus.com/ggtutorials/screenshot_001-00004.png
www.zombieshortbus.com/ggtutorials/screenshot_001-00005.png
06/21/2007 (7:11 pm)
Ugh...scripting is just too much effort:
More Pics:
www.zombieshortbus.com/ggtutorials/screenshot_001-00001.png
www.zombieshortbus.com/ggtutorials/screenshot_001-00002.png
www.zombieshortbus.com/ggtutorials/screenshot_001-00003.png
www.zombieshortbus.com/ggtutorials/screenshot_001-00004.png
www.zombieshortbus.com/ggtutorials/screenshot_001-00005.png
#14
06/21/2007 (7:17 pm)
@Jeff: Wow, fantastic! I'm away on a business trip, so I'll have to check this all out when I return. It sounds like the perfect solution. I appreciate you taking the time to implement that!
#15
Michael do you think to release this AFXWeapon GUI as a resource?
;)
02/06/2008 (6:41 am)
Wow! Fantastic! :)Michael do you think to release this AFXWeapon GUI as a resource?
;)
#16
If others are interested in afxWeapon Creator, I can add that to my list of projects to complete this year.
02/06/2008 (6:47 am)
@JoZ - Well, right now I'm focusing on the AFX Creator tool. The afxWeapon system still needs some major adjustment and additional features before developing this tool. The demand and interest for AFX-C is currently higher than the afxWeapon Creator. However, both tools share the same critical code. If others are interested in afxWeapon Creator, I can add that to my list of projects to complete this year.
#17
And I wanna ask you something about your courses on TorqueSchool... but I'll ask for it in your proper thread for that... ;)
JoZ.
02/06/2008 (7:07 am)
I know it also, every of your projects are absolutely fantastic tools! EhehehAnd I wanna ask you something about your courses on TorqueSchool... but I'll ask for it in your proper thread for that... ;)
JoZ.

Torque Owner Rex
BrokeAss Games
A question about the bounding box origin as mountPoint; why was this done and not a specific "mountPoint" node? I'm primarily an Artist with Scripting skills......I know about the default mounting point if none is supplied, just curious why?