I have no idea, i try the to play an animation for a time if a value change fast
for example if current speed = 10 and in 2 seconds the speed goes >= 100 then play my animation.
So i need to know the current speed = currentSpeed , then we have the float 2f(seconds), and the (change)powerSpeedValue >= 100
if (powerSpeedValue >= currentSpeed (for 2 seconds)){
//play Animation
}
something like this?
Definitely not.
If the change can happen at any time, you’d need to keep track of every speed during the last 2 seconds, and compare the values every frame. If it’s a one-of, it’s much easier, and you could just run a coroutine to check after two seconds.
Ah I store the current speed . And after 2 seconds I ll check the “new” current speed against the current speed. And when the difference is greater for example 100 I can play my animation.
? Makes more sense?
Pretty much. You’d need to store all the values in the past 2 seconds though in order to keep track of it, or you could just poll the values less and only do it once every 2 seconds.
I give it a try and report back
This works for me, but another animation is overwrite it, so i need to wait that the animation is ended before we start the next nanimation
//check that we have a hard pedal in watts
currentPower = centralSensor.power;
if (currentPower - lastPower >= 100)
{
wheelsAnimator.Play("Base Layer.ANIM_Racing_Bike_Start_Hard_Pedaling");
riderAnimator.Play("Base Layer.ANIM_Male_Cyclist_Start_Hard_Pedaling");
lastPower = currentPower;
Debug.Log("StartHardPedaling");
}
for every frame powerSpeedValue >= currentSpeed is true you subtract Time.deltaTime from a field, and when that condition is false you set the field to 2f. if it reaches zero or lower execute what you wanted to do.
1 Like