Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: ToxicFrog on February 16, 2018, 11:23:24 PM
-
Hello Playmaker Friends,
I've built a timer that is intended to display a countdown in seconds, while showing the decimal value of a second.
In other words, 3 seconds would look like this:
2:59
and the '59' would rapidly count down (from 59 to 0 in one second) before changing to '1:59'.
I've built the timer, and it works functionally, as in all the countdown digits behave as intended.
My problem is that I cannot make the game accurately count down a proper second.
I have a 'WAIT' state, that waits for 0.01666 seconds (the decimal value of 1/60 of a second). And it WILL NOT count down fast enough. Each 'second' actually take roughtly 1 1/2 seconds.
I set the Project Settings -> Time -> Fixed Timestep to 0.01 and 0.016, and it doesn't fix the problem. It will NOT count down in increments of 0.01666 seconds.
When I change the WAIT state to 1 second, it perfectly counts down in 1 second increments. But I need it to count down in increments of 0.01666 seconds, and it just will not do it.
Any suggestions?
Thanks in advance, and I'll reply with results from any suggestions!
-
Use "Convert Seconds to String" action. It will give you accurate milliseconds. Just use a float variable as the number of seconds. Works like a charm.
-
Thanks for the reply, antibob.
But, I guess I didn't explain my problem accurately. My timer's DISPLAY is working fine. I have an FSM setup to convert 2 INTs to strings, which are shown as text on a canvas.
I have the INTs labeled 'Prefix' and 'Suffix', so the String is created like this:
[Prefix]:[Suffix]
So, 3 seconds looks like this:
2:59
I have a WAIT action, set to wait for 0.01666 seconds, after which it subtracts 1 from the suffix. So it SHOULD do this:
1. Build String from [Prefix]:[Suffix]
2. Update text (every frame, displays 2:59)
3. Wait 0.01666 seconds
4. Subtract 1 from suffix (now 58)
5. Update String (now 2:58)
This counts down so that the Suffix is a very quick countdown from 59 to 0 every second.
My problem is that when I use a WAIT action, it will not wait for 0.01666 seconds.
For whatever reason, it will wait for longer than 0.01666, and it's not giving me an accurate second-based countdown. So it appears my problem is with the WAIT action.
I thought changing the project's Fixed Timestep from 0.02 to 0.01 would fix it, but it did not.
Does this make sense?
-
Additional info:
I've done some experimenting, and it looks like the WAIT action just will not work as expected if the wait time is less than 1.
*EDIT:
That may not be accurate.
I tried another test, where I animated the timer object. I animated its position on frames 0 and 1 (with a step of 60), so that it would play its animation in 1/60th of a second. Upon finishing the animation, the next state would add -1 to the Suffix INT.
Unity is not keeping up with the timing. The countdown is just not going fast enough.
Any thoughts or suggestions as to what might be causing this?
-
I'd suggest moving all the logic to floats and see if that helps with precision.
All numbers can drift a bit but floats give you a little more control over math functions. Also, consider building your own time function based on a float that governs your "Time". It may still be relative but it may give you a bit more control.
Finally, Have you looked at Chronos https://assetstore.unity.com/packages/tools/particles-effects/chronos-31225 (https://assetstore.unity.com/packages/tools/particles-effects/chronos-31225)? It has it's own time manager. I'm not sure if it would help in your specific situation but it's worth a look.
-
I found a good solution.
As I said, I could not get Unity to count down accurately in increments less than 1 second.
So, I found 'Clocks and Timers' on the asset store, which lets you create a timer with millisecond precision. It's got some Playmaker hooks, and all the elements from the script are accessible enough that I was able to get the desired result.
I appreciate your help!
ToxicFrog
-
Hi,
Very good, I am glad you found a solution, and thanks for letting us know :)
Bye,
Jean