- Home /
How to make a variable fall/rise over time?
I'm somewhat new with scripting. I'm scripting a jump script and I'm trying to make it so that whenever the player is in the air a variable goes up, and that variable would negatively affect their jump height. So I wrote
void Update ()
{
if (isgrounded && (test>0) == true) ;
{int test =(test - 1);}
if (isgrounded == false);
{int test =(test + 1);}
I realize that even if that worked it would increase/decrease the variable per-frame, rather that per-second, I was going to try to fix that later, maybe by making it a float
if (isgrounded == false);
{float test =(deltaTime*(test + 1));}
any help you can give would be greatly appreciated
I'm using a rigid body with a script that adds forces based on player inputs
Not exactly, I was trying so after being in the air for a period of time the strength of the players jump would be reduced.
So if you mashed the jump key your jumps would become progressively less powerful.
Although, I do want to make gravity later, and the ability to increase/decrease variables over time would be good for that too.
is there a way to increase a variable by "x" per-second?
is there a way to increase a variable by "x" per-second? --Dijit
@Dijit : Yes. If you search google or this board you'll find a ton of code showing how this is done.
Answer by guido123 · Apr 01, 2014 at 12:05 PM
to increase your amount per second it should be like this.
float test = (test + (Time.deltaTime * 1));
you could also try invokerepeating