Using delta time on an actor in Blueprint

I’m recreating flappy bird and have finished the game, however I’ve found that when I run it outside of the editor everything is super fast. I know I need to multiply by delta time, as I’ve seen so many say before, but I just can’t figure out how to do it.
The attached image works just fine in the editor. How can I make this movement independent of frame rate?

EDIT: This is the script for the movement of the pipes the player has to dodge

What you want is something like:

// pseudo-code

ActorLocation += speed * deltaTime;

// or

s = speed * deltaTime;
ActorLocation = ActorLocation + s;

“speed” here would be your -15.0 on the Y axis.

So how to do this in the Blueprint?

You can start by multiplying your speed by “Delta Seconds”. Then add the result to just the Y value of the actor’s location.

The actor location is a Vector consisting of 3 floats (X, Y, Z). On the “Get Actor Location” node, right-click the Return Value pin and split the pin. Then you can drag off the Y pin to create an addition node. Split the “New Location” pin the same way and pass the result of your addition.

[Edited to fix logical mistake] (see screenshot below)

If you drag off the return value of “Get Actor Location”, you’ll can search for “break” which will create a node that “breaks” the Vector into its 3 parts. Then you can drag off the Y node and create a multiply node (to multiply by the “Delta Seconds” given by Event Tick. Then on the “Set Actor Location” node’s “New Location” pin, right-click and split the pin. You can then pass the result of your multiplication to the Y. And you probably also want to connect the X & Z from the “Get Actor Location” node to keep those as they are.

After doing this, you may need to increase the -15.0 value because it will now be reduced by Delta Time.

I tried to follow your instructions but I’m definitely misunderstanding something. Running this just plops the pipe on top of the character and ends the game lol thank you for helping btw!

I thought running:
NewLocation = GetActorLocation + (0, -15, 0) * DeltaSeconds;
would work but it definitely doesn’t. I’m obviously missing something lol

If we assume the editor instance ran at 60 FPS, the tick would have applied 60 times per second. So, the pipes moved -15 * 60.

Say your game outside the editor runs at roughly 180 FPS, which means the pipes would have moved at -15 * 180.

To counteract this effect, you can take into account delta time. Delta time tells you how much time has passed since last tick. So, if a game runs at steady 60 FPS, the delta time value, in seconds, would be 1/60, or 0.0166666.

If you only multiply the -15 with Delta Time, this will make the movement of the pipes framerate independent (for the most part anyway), but it will also slow the movement of the pipes down by a factor of 60. So, if you playtested the game at around 60 FPS, the approach is to take the -15 and multiply it by 60. In the end you would move the pipes by -900 * Delta Time for every tick.

So now, if the game runs at 60 FPS, it will move the pipes by (-900 * 0.01666) or -15 every tick, for a total movement of -900 per second, as ticks occur 60 times per second.

If your game runs at 180 FPS, it will move the pipes by (-900 * 0.00555) or -5 every tick, for a total movement of -900 per second, as ticks occur 180 times per second.

Don’t try to plug wires into each other randomly, your first graph makes way more sense except it doesn’t take framerate into account, in the second, you’d have to ask yourself what you are even multiplying.

Edit: Also don’t use delays in tick to destroy the actor. Either check the Y position and see if the value is too low, then destroy them, or use some sort of a trigger volume to destroy the pipes once the pipes touch it.

2 Likes

I tried to follow your instructions but I’m definitely misunderstanding something.

Sorry, I think I have explained it wrong the first time. This is what I meant…

Also, I do notice in your original screenshot, that you have a Delay node after “Set Actor Location”. I’m not sure what that is for, but you may want to disconnect it for a simpler test.

1 Like

Thank you very much, this works!

1 Like

Thank you for explaining, this was very helpful

1 Like