playMaker

Author Topic: How to use actions with "Per second" options correctly?  (Read 1366 times)

Mupp

  • Full Member
  • ***
  • Posts: 167
How to use actions with "Per second" options correctly?
« on: September 27, 2021, 11:45:48 AM »
I have a huge issue with timings at different framerates. The player moves too fast, jumps too high and countdowns go too fast at low framerates.

Most of my logic is too complex to only use one state so I usually create state loops that cycles once per frame. But if I use an action that has a "Per second" option, like float add/subtract, it just doesn't work consistently at different frame rates.

Do you need to only use one state for those actions and also check "Per frame" to get a good result? I do this for adding force but it seems you move too fast at low fps.

I thought Playmaker would automatically make sure that the update is in the correct type since you have no option to set update type on most actions.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
    • jinxtergames
Re: How to use actions with "Per second" options correctly?
« Reply #1 on: September 28, 2021, 11:38:09 AM »
Hi.
You can use Run fsm with templates, this way you can stay in 1 state and still loop things.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: How to use actions with "Per second" options correctly?
« Reply #2 on: September 28, 2021, 12:05:45 PM »
Ok, I will check it out.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: How to use actions with "Per second" options correctly?
« Reply #3 on: September 29, 2021, 10:17:58 AM »
No I can't make this work, the difference I get at different framerates significantly impacts gameplay. For example, a countdown timer can have a difference of up to 2 seconds realtime between 30-144 fps. It does not matter if it's a stete loop or a single state that repeats every frame.

When searching for this problem, all I get is just multiply with delta time, in fixed update if it's physics. On this forum I get almost no relevant info at all.

Is this an editor issue?
I also have a script that limits framerate so I can test but even with that disabled I get the same result if I lower the framerate by having a complex fsm open that slows down the game.

So I could use an example how to setup anything timing related that creates the best possible result.
I can't be the only one to notice this so I must be doing something wrong.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
    • jinxtergames
Re: How to use actions with "Per second" options correctly?
« Reply #4 on: September 29, 2021, 10:49:42 AM »
Hi.
Frames can always fluctuate especially on different unit (like i new pc versus a old pc)

There is a vsync setting that limits to 60 frames, but it could still fluctuate. (especially on slow units )

For a countdown timer. there is an action on the ecosystem that i made.
and it uses delta time.

as far as i know, most (if not all) Physics actions are using Fixed update.

Action like Float Add (and turn on per second) are using delta time.

But adding Force is not something consistent.
Velocity is way more consistent, but has Less effect on Physics materials.

our player used to have a "Force Impulse" for jumping and we had a lot of issues.
Now we use velocity with a float tween to 'animate' the curve and its very consistent compared to force.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: How to use actions with "Per second" options correctly?
« Reply #5 on: September 29, 2021, 11:57:19 AM »
Oh, I'm using force impulse too. Good thing too know that I'm not insane. :)

Though I really don't wanna use any physics at all so I set velocity to 0. All I want from the physics engine is to block objects from entering each other and I've found no other way.
Do you have a suggestion?

Still have issues with countdown though, gonna check your action.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
    • jinxtergames
Re: How to use actions with "Per second" options correctly?
« Reply #6 on: September 30, 2021, 10:49:31 AM »
Hi.
Can you give some more info on the project maybe a short video on showing these issues like objects entering, game type (vr / 2d / 3d)
you can pm it to me if you don't want to show public.

just for me/us to understand why you would use Set Velocity instead if 'is kinematic' for example.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: How to use actions with "Per second" options correctly?
« Reply #7 on: October 01, 2021, 11:28:25 AM »
I can show some examples of my setup since all a video would show is that these problem exists. I won't post all the FSMs since they probably will not make any sense unless you go into detail.

In the first pic you see the first part of the jump FSM. It moves the player up while counting down, then it moves to the next part, counts down and so on untill the jump is done. I've tried to get delta through checking "per second" in subtract, get it from the time info action in the same state and now from a dedicated FSM. At 30 fps you can't always make the jump you see in the pic.
In the top left you see fps and horizontal speed. The speed is calculated from smoothed fixed delta divided by distance per frame from a single state FSM. This gives a very good result at high fps, only off by 0,01 or so from the force vector. At 30 fps this is horrible wrong showing almost double the speed some frames.

In the second pic there's a loop that cycles once per frame. I tried the same ways as in the jump FSM to get delta, but at low fps this timer can differ almost 1-2 seconds from high fps. In the wait state I use a next frame event action.

In the last pic the force is applied once per frame. The force is calculated each frame and is combined from different FSMs. I don't use delta time on this final vector in any way except what the force action does. Setting velocity or adding force makes no difference, you move way faster at low fps.

I have fiddled with the time settings, but all that seems to do is move the point where these time differences happens.

I also have a script to limit fps, but enabling or disabling it doesn't seem to make a difference. Can vsync mess with timings?
Code: [Select]
using UnityEngine;

public class Framerate : MonoBehaviour
{
public int targetFrameRate = 144;
public int vSync = 0;
private void Start()
{
QualitySettings.vSyncCount = vSync;
Application.targetFrameRate = targetFrameRate;
}
}

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
    • jinxtergames
Re: How to use actions with "Per second" options correctly?
« Reply #8 on: October 02, 2021, 09:22:07 AM »
Hi.
Set velocity with a vector 3 is probably not a good way.

use a fsm for forward / side movement and only set the velocity to that axises.

then on another fsm you can set the up velocity for the jump.
for the jump you can use a tween float (up velocity)  to make the curve of the jump more smooth.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: How to use actions with "Per second" options correctly?
« Reply #9 on: October 02, 2021, 06:33:21 PM »
But I do calculate each axis in separate FSMs. Can combining them into one vector mess up timings? Does it really matter where the action adding force is? It's updated once per frame so why does it matter if I combine them, it would still be the exact same numbers.
This does not make any sense to me and it does not explain why the non-physics counters differs at different fps.

10high

  • Playmaker Newbie
  • *
  • Posts: 33
    • Cult Manager - Google Play
Re: How to use actions with "Per second" options correctly?
« Reply #10 on: October 07, 2021, 09:24:09 AM »
I'm making a WebGL game and recently tested it on itch.io for the first time and also noticed that two GOs that I move with the "Translate" action are considerably slower when playing in the browser on itch.io than when testing in the editor.

Both are set to translate by a certain distance per frame (with seconds NOT checked).

I looked at the "Translate" action and it does seem to use delta time, so I'm also curious about how that works? If it is delta time, shouldn't it always be the same, whether in the editor or (in this case) a browser?
Cult Manager