- Home /
Animation depending on int
I have made a cannon that fires at a certain strenght depending on how long you hold down the space key. What I want is for the cannons "charge" animation to depend on the actual charge int. So the animation will only reach it's end if you charge the cannon to maximum power. Any tips on how to do this?
Why are you modelling a continuous value with an int, may I ask? Shouldn't that kind of thing be a double or float?
No real thought into it. Int handles numbers and I needed a variable to handle numbers so I used an int. I'm kind of fresh into this whole program$$anonymous$$g thing.
int manages whole numbers only- you should use a float for continuous values.
Answer by syclamoth · Mar 13, 2012 at 09:13 AM
How about this?
animation["NameOfAnimation"].normalizedTime = currentPower / maxPower;
Put this in Update, and it will seek through the animation as you charge your cannon!
Wow, that's pretty cool ... a great little piece of code to play around with ... ;)
Yeah thanks. Still have some errors with the code but I think this solves the problem.
Whoops! I screwed up! maxPower and currentPower are the wrong way round! It should be
currentPower / maxPower;
The other thing can cause divide-by-zero errors... Embarrasing thing to trip up on, really.
Best part about that picture is, it isn't even shopped.