Do stuff not based on FPS

How do i make it so stuff runs at the same speed, even if the FPS is low?

See Consistent movement regardless of FPS?

One method

Run one forever loop that waits a duration and then sends out a broadcast

The use when xxx received blocks to do something

Ditch the loops
You can use the timer block and <when timer>0.2><reset timer><dosmth>

I see, but how exactly do i get the FPS?

Divide by timer if you don't reset it

you can get the time between frames, but that doesn't really make it clear how to actually use that to keep things the same. you probably want physics equations:

if you're moving something around, you probably have position, velocity (speed), and acceleration. note that velocity is how fast the position is changing, and acceleration is how fast the velocity is changing.

let's say every frame this code runs:
SET position TO position + velocity
SET velocity TO velocity + acceleration
(i'm not using the change blocks because the set blocks work with lists, which is nicer to use because you don't need seperate variables for x and y)
this doesn't work independently from framerate because the speed of something measures how much the position changes after some amount of time. if you watch a car, it'll be farther away from you the longer you wait (hopefully a car isn't driving towards you)

this is better:
SET position TO position + (velocity * time)
SET velocity TO velocity + (acceleration * time)

you can get the time from the CURRENT [TIME IN MILLISECONDS v] blockto measure how long it's been since the last time you ran the physics. use a variable to set what time it is when running physics, and subtract them after.

note that you only need to get the time since the position, velocity, and acceleration you're using, you can get where/how fast an object will be by just using any time value you want, and not setting the position/velocity.

there's one issue with the last code though, if your acceleration is really high, but velocity is 0, the position should still change because over that course of time, the velocity would end up increasing. you need to factor it in like this:
SET position TO position + ((velocity + (acceleration * time / 2)) * time)
SET velocity TO velocity + (acceleration * time)

to actually find equations like this, just look up physics math equations. they always need to be VERY precise into the future and don't use loops like programmers. you might want to find things like calculating for friction and such.

anyways, you probably need to move a player around and have gravity. gravity is just a constant acceleration, so do something like set y acceleration to -1. for movement, i haven't actually made platformers in a while, i don't know a perfect way to do that. it's probably good enough to set the acceleration based on how far the current velocity is from how fast the player should be moving. be careful when changing the velocity or position directly, if it's supposed to be instant and a single set that's fine, but mess things up too much and you'll likely go back to differences between framerate.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.