help with weapon IFL or texture animation
by deepscratch · in Torque 3D Professional · 09/12/2009 (8:17 am) · 10 replies
hi there,
my game has no weapon HUDs, no crosshairs, and no preview images of the currently selected weapon, the game's story line does not allow this kind of "technology" for the main player.
however, I would like to be able to keep tabs on how much ammo I have in my currently selected weapon.
my idea is to have an IFL or texture animation on the weapons magazine, idealy a simple bar that shows the ammo by changing color as your ammo gets wasted.
I did a quick photoshop to show the effect I'm after.
any help on this would be great.

my game has no weapon HUDs, no crosshairs, and no preview images of the currently selected weapon, the game's story line does not allow this kind of "technology" for the main player.
however, I would like to be able to keep tabs on how much ammo I have in my currently selected weapon.
my idea is to have an IFL or texture animation on the weapons magazine, idealy a simple bar that shows the ammo by changing color as your ammo gets wasted.
I did a quick photoshop to show the effect I'm after.
any help on this would be great.

About the author
email me at medan121@gmail.com
Recent Threads
#2
09/12/2009 (8:43 am)
Plastic Gem 33. I used that resource a while back for blood-meter IFL's on various weapons, but it may need some porting... the particular weapon design of that project was that it/they fed upon the blood/lifeforce of your enemy and became stronger/charged as you did damage -- kind of the opposite of ammo but similar all the same ;)
#3
09/16/2009 (4:58 am)
I thought animations like that are already built into the thread system already in place. They use a state based engine. This state based engine can be executed from a number of places. Scripts / Animation sequences finishing / triggers. Why not just make a IFL sequence on your model that shows your ammo getting low and then play it based on a script callback. Then when you fill it up play the thread in reverse in a script callback. If you want script examples I'll see what I can come up with.
#4
sounds like a good option, yeah, if you can come up with a script example, that would be great!!!
09/16/2009 (11:45 am)
@JesseL,sounds like a good option, yeah, if you can come up with a script example, that would be great!!!
#5
//First you make the sequences for the gun with the ammo loaded.
your normal sequences
Add a couple of blended sequences //you have like 32 something max so why not use them
Sequences:
Loaded
Reload
Unload
Ready
Ambient
//these are the ones for ammo these are IFL statements
Blended Sequences:
ammoFull
ammoOneForthEmpty
ammoOneHalfFull
ammoOneForthFull
ammoEmpty
At this point you can make them slowly blink up or Quick Glowing blink at begining of sequence and at the end of one or whatever you want it to look like.
Ok rules to state machine scripting
First you have 30 states that any shapeBaseImageData can have. I think that will be plenty for what you want to do seriously.
example
I hope thats enough for you to get the Idea.
09/16/2009 (5:38 pm)
OK technically you can play 4 threads on any shapebaseImageData object. I'm pretty sure you've seen the weapon in Tribes2 power down before right? When they run out of ammo they powered down. This was all scriped with a statemachine. //First you make the sequences for the gun with the ammo loaded.
your normal sequences
Add a couple of blended sequences //you have like 32 something max so why not use them
Sequences:
Loaded
Reload
Unload
Ready
Ambient
//these are the ones for ammo these are IFL statements
Blended Sequences:
ammoFull
ammoOneForthEmpty
ammoOneHalfFull
ammoOneForthFull
ammoEmpty
At this point you can make them slowly blink up or Quick Glowing blink at begining of sequence and at the end of one or whatever you want it to look like.
Ok rules to state machine scripting
First you have 30 states that any shapeBaseImageData can have. I think that will be plenty for what you want to do seriously.
example
datablock shapeBaseImageData( deepsExample ) {
stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "gunLoaded"; // We have ammo so make it look like it.
stateTransitionOnNoAmmo[0] = "gunEmpty";
stateScript[0] = "checkAmmo";
stateName[1] = "gunLoaded"; //this would be value 0
stateSound[1] = gunReadySound;
stateSequence[1] = "gunAmmoFull"; //always set to full then decrease.
stateScript[1] = "checkAmmo";
//at this point you can call a script to make it look like you have whatever amount of ammo you want to have.
stateName[2] = "gunEmpty";
stateTransitionOnAmmo[2] = "gunReload";
stateTransitionOnTriggerDown[2] = "dryFire";
stateScript[2] = "checkAmmo";
stateName[3] = "dryFire";
stateTimeoutValue[3] = 1.0; // 1 second
stateTransitionOnTimeout[3] = "gunEmpty";
stateSound[3] = gunEmptySound;
stateScript[3] = "checkAmmo";
stateName[4] = "gunReload";
stateTransitionOnNoAmmo[4] = "gunEmpty";
stateTransitionOnTimeout[4] = "gunLoaded";
stateTimeoutValue[4] = 0.8;
stateAllowImageChange[4] = false;
//this prevents your weapon from leaving your hands while this state is running;
stateSequence[4] = "gunReload"; //this runs a sequence on your weapon named "gunReload";
stateScript[4] = "checkAmmo";
}
function deepsExample::checkAmmo(%this, %obj)
{
// function to check for ammo level according to inventory
// place the sequence on the correct sequence for that ammo level
//calculate weapon ammo percentage
%ammoPer = %this.ammo / 100; //whatever
if(%ammoPer == 1.00)
{
%obj.stopThread(3);
%obj.PlayThread(3, "ammoFull");
}
else if(%ammoPer >= 0.75 && %ammoPer < 1.00)
{
%obj.stopThread(3);
%obj.playThread(3, "ammoOneForthEmpty");
}
else if( %ammoPer >= 0.5 && %ammoPer < 0.75 )
{
%obj.stopThread(3);
%obj.playThread(3, "ammoOneHalfFull");
}
else if( %ammoPer >= 0.25 && %ammoPer < 0.5 )
{
%obj.stopThread(3);
%obj.playThread(3, "ammoOneForthFull");
}
else if( %ammoPer >= 0 && %ammoPer < 0.25 )
{
%obj.stopThread(3);
%obj.playThread(3, "ammoEmpty");
}
}I hope thats enough for you to get the Idea.
#6
If you implement some of the Plastic Games Gem of the Day stuff for threading. You could use a pause and setThread. Then all you would have to do is create one blended animation sequence from 100% to 0%. You could have the %this.setThread(3, %ammoPer); and be done. Its upto you!
09/17/2009 (4:41 am)
Side note:If you implement some of the Plastic Games Gem of the Day stuff for threading. You could use a pause and setThread. Then all you would have to do is create one blended animation sequence from 100% to 0%. You could have the %this.setThread(3, %ammoPer); and be done. Its upto you!
#7
only thing is that shapeBase has the console functions for stopThread and playThread.
shapeImage(a weapon), does not.
09/17/2009 (2:32 pm)
thats a beautiful script there JesseL,only thing is that shapeBase has the console functions for stopThread and playThread.
shapeImage(a weapon), does not.
#8
::checkAmmo(%this)
to
::checkAmmo(%this, %obj)
and
%this.stopThread(3);
%this.PlayThread(3,
to
%obj.stopThread(3);
%obj.PlayThread(3,
now seems to be getting somewhere, great.
09/17/2009 (2:54 pm)
ok, changed::checkAmmo(%this)
to
::checkAmmo(%this, %obj)
and
%this.stopThread(3);
%this.PlayThread(3,
to
%obj.stopThread(3);
%obj.PlayThread(3,
now seems to be getting somewhere, great.
#9
09/18/2009 (4:08 am)
I updated those changes to my post as requested. It was just an example I didn't actually test it or anything.
#10
09/18/2009 (7:23 am)
well its a awesome example.
Associate Fyodor -bank- Osokin
Dedicated Logic
Hack into ShapeBaseImage and add a code for additinal thread-processing + a couple of variables: bool flag to ena/disable feature, float from 0 to 1 to show progress of animation. Ghost that data to client via network and add rendering code.
As far as I remember the code in ShapeBaseImage (don't have sources at hands atm) it should be quite easy to add such feature.
That resource could help you too (on how to hack ShapeBaseImages): http://www.garagegames.com/community/resources/view/14920
P.S. You can even add "enableAmmoAnimation" & "ammoAniProgress" vars into Player or ShapeBase class for easier processing, as you can always get mounted images like so:
for( U32 slot = 0; slot < ShapeBase::MaxMountedImages; slot++) if( (ShapeBaseImageData* data = getMountedImage(slot)) != NULL ) { ... your code }