PDA

View Full Version : HCE [Tutorial] Animated Projectiles



CtrlAltDestroy
June 20th, 2010, 05:20 PM
As some of you may be aware, the animation graph field in the projectile tag doesn't do anything:

http://img97.imageshack.us/img97/8038/75562281.jpg

So, I developed a little work around.

Pros:

Animations are cool.

Cons:

Can't animate markers, meaning things like smoke trails and whatnot won't sync with the model's animation.
Polycount increases with each frame of the animation. LODs fix this though.


Take your model--I'll be using Infinity Ward's throwing knife from Modern Warfare 2:
http://img688.imageshack.us/img688/3074/98320569.jpg

Duplicate your model for each frame of your animation, and position/rotate/scale/fuck around with each 'frame' accordingly:
http://img202.imageshack.us/img202/2338/14841491.gif
**Note: Your frame count should be a power of two ideally (for example, I have a total of 8 frames above), unless you want to get creative with your texture's dimensions--which I won't get into... just stick to a power of two.

Take your model's texture:
http://img149.imageshack.us/img149/2075/59913501.jpg
... and tile it horizontally by the number of frames you have:
http://img149.imageshack.us/img149/6564/23927513.jpg
Remember how I said your frame count should be a power of two? Yeah, this is why.

Re-UV each 'frame' of your animation to the new texture accordingly:
http://img149.imageshack.us/img149/7518/49215228.jpg

Then, black out all but the first frame in your texture (make sure you do so with your alpha channel as well):
RGB:
http://img823.imageshack.us/img823/3544/44354056.jpg
Alpha:
http://img819.imageshack.us/img819/2135/78775148.jpg

Your model should look something like this now:
http://img517.imageshack.us/img517/4117/52611468.jpg
**Note: The black areas will appear completely transparent ingame.

OK, export your model/compile your bitmaps and all that noise. Open up your model's shader_model tag:
http://img249.imageshack.us/img249/8208/93376168.jpg
The u-animation source should be 'A out', and the function should be 'one' (default). Your scale should be set to -1 repeats, otherwise your projectile will animate backwards.

Now, onto the projectile tag...
Here's what your A out function should look like:
http://img189.imageshack.us/img189/7363/67584109.jpg
The function should be set to slide. Your period dictates how long the entire animation takes to make one loop. I have it set to 0.2, therefore each frame lasts 0.2/8 = 0.025 seconds (40 fps). Your step count should be your frame count plus one. What this does is quantize your texture scrolling animation such that each 'shift' moves the texture over by one tile, as opposed to smoothly scrolling it (bad).

** OPTIONAL
If your projectile becomes embedded into a surface after it impacts something, as opposed to detonating/disappearing (i.e.: the throwing knife), then you probably don't want the projectile to continue animating after it becomes embedded:
In your A out function:
http://img208.imageshack.us/img208/4088/69158957.jpg
... set the scale result by to 'B out'.

This is what your B out function should look like:
http://img63.imageshack.us/img63/5884/79686557.jpg
... and the rest of the projectile tag:
http://img337.imageshack.us/img337/5416/49238924.jpg
I hope the functionality of this... function should be intuitive to figure out. Basically, what this means is, if the projectile is not airborne, don't animate.

And voila:
http://img256.imageshack.us/img256/3842/knife.gif

Limited
June 20th, 2010, 05:25 PM
You love jumping through hoops to get things to work :) Great job.

PopeAK49
June 20th, 2010, 06:56 PM
That is the coolest thing I have ever saw for halo ce.

EX12693
June 21st, 2010, 01:12 AM
I want that plasma pistol.

Con
June 21st, 2010, 01:56 AM
Very clever. To save texture space, couldn't you just rely on tiling for the diffuse but have a wider, separate alpha mask that scrolls through? It's similar to what I did for the lightning in precipice except the lightning planes didn't need to tile their diffuse. The scrolling mask would just multiply onto the diffuse map's alpha.

http://img708.imageshack.us/img708/4686/39977158.jpg
gray is the mask, black is the tiling diffuse

CtrlAltDestroy
June 21st, 2010, 02:26 AM
That would actually waste more texture space as DXT compression ratios are not based on the bitmap's texture complexity (as a compression scheme such as JPG would be). For example, a completely white, 512 * 512 image compressed with DXT1 would be the exact same size as the default assault rifle diffuse. This way, I'm only using one texture as opposed to two (just the diffuse rather than the mask + the diffuse).

Shock120
June 21st, 2010, 02:58 AM
Very interesting.
A shuriken would look nice in this.

/offtopic
That hud and that plasma pistol have extremely nice detail. =O

Dwood
June 21st, 2010, 03:32 AM
Is it possible to make a projectile spiral with that method or is it limited to a horizontal axis?

Inferno
June 21st, 2010, 01:59 PM
A spiral could be done with this. But it wouldn't look right since the contrail would just stick in the center.

Kornman00
June 21st, 2010, 03:14 PM
Hey CAD, have you ever thought about changing the projectile of a weapon post-cache-build to maybe some sort of animated scenery (plus some other magic to make the projectile work)? That or just attach an animated scenery object to an invisible projectile?