PDA

View Full Version : basic expression help, counting down


misterwolfy
10-02-2010, 02:22 PM
I have an animated attribute, loc.num. When loc.num reaches the value of 1, I want to trigger an another attribute loc.num2 to be 1. Then I want the value of loc.num2 to count down in incriments of .1 at each frame until loc.num2 becomes 0 or loc.num becomes 1 again.

The code is below. The last else statement is giving me an error. I think I need something like this to keep loc.num2 from dipping below 0, into negative numbers.

Can anyone help with the solution?


if ( loc.num >=1)
{
loc.num2 = 1;
}
else
{
if (loc.num2 >0)
{
loc.num2 = loc.num2 -.1;
}
}
else
{
loc.num2 = 0;
}


Thanks for reading!

NaughtyNathan
10-02-2010, 02:48 PM
hey wolfy, your boolean logic is flawed.. you can't have two elses after one if, which is what you have here:

if ( loc.num >=1)
loc.num2 = 1;
else
if (loc.num2 >0)
loc.num2 = loc.num2 -.1;
else // where should this be..?!?
loc.num2 = 0;

I've removed the { } for clarity (you don't need them anyway when their scope only contains one line of code!)

you can see the error (hopefully) and I assume the last else should belong to the if scope above it, in which case your } and { are in the wrong place.
:nathaN

misterwolfy
10-02-2010, 03:14 PM
Thanks NNathan!

This seems to work perfectly now. Goes to 1 then counts down to 0.

Wolfy


if ( loc.num >=1)
loc.num2 = 1;
else
if (loc.num2 >.1)
loc.num2 = loc.num2 -.1;
else loc.num2 = 0;

misterwolfy
10-02-2010, 03:33 PM
I have another question if you feel up to it ;).

is there an easy way to make my numbers ease in? so instead of going 1, .9, .8, .7, .6, .5, they would count more like 1, .75, .6, .5, .55, .4, .475, etc? I suppose I can use a curve, but not sure how. Math would be elegant too.

Thanks for all your help!!

mduvekot
10-02-2010, 04:45 PM
See http://www.thnkr.com/wiki/index.php?title=Ease-in_and_ease-out

CGTalk Moderation
10-02-2010, 04:45 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.