How does the velocity work

i really need to know this, because i’m porting one of my games to another engine. i’d highly appreciate an explainition on how it actually works.

3 Likes

it instantly changes it constant speed to something acceleration increases the speed friction slow it down to zero velocity in both directions

i know THAT part, i mean like how many pixels it moves the sprite each frame and why it just goes turbo mode whenever the FPS slows down and all that weird stuff that shouldnt happen
vx = 1 is not equal to 1 pixel on the x axis per frame, its weird.

1 Like

@babol the velocity is in pixels per second, not pixels per frame. similarly, acceleration is in pixels per second squared

all the physics are adjusted for the amount of time that has passed since the previous frame. e.g., if a frame takes three times as long to render, the physics will move the sprite by three times the distance

1 Like

well, what was the reason for it to be pixels per second and not pixels per frame?
(and, could you guys add a pixels per frame velocity system? maybe a toggle between the 2 for sprites)

@babol this is what most modern game engines do; it makes it so that gameplay seems natural even with a variable frame rate. otherwise, your game might run faster on a faster computer.

1 Like

but wouldnt it make more sense to add the other one, considering makecode arcade is meant to recreate the arcade game feel? and what about the request? it would really help me out with some projects.

i think this is probably too niche a feature for us to add. that being said, you can sorta force this behavior if you add some js that looks like this to your project:

const LOCKED_FPS = 30;
game.currentScene().eventContext.registerFrameHandler(-1, () => {
    game.currentScene().eventContext.deltaTimeMillis = Math.idiv(1000, LOCKED_FPS);
});

this will lock the game physics to the frame rate by setting a constant time between frames. it won’t make it so that a velocity of 1 equals 1 pixel per frame, though. you might be tempted to change the LOCKED_FPS variable to 1 to get that behavior, but it won’t work because our physics engine has a maximum time step it supports and it’s less than one second.

working in pixels per frame would be awkward anyway. do you really want to give a sprite a velocity of 0.5?

1 Like

working in pixels per frame would be awkward anyway

i personally have to disagree with that since i’ve worked with pixels per frame is what i’ve worked with my entire life and it just works better considering the fact that its actually consistent and doesnt make you wanna tear your lips off when trying to port games (i recall spending hours trying to get the movement to be accurate when porting a game of mine to GMS2 by finding a multiplier, unaware that its not pixels per frame but pixels per second)

Why can’t you just move the character a certain amount every frame?
Let MyVelX = 1
On game update, change mySprite [position x] by (MyVelX)

This really isn’t that hard to do. Velocity is just increasing VelocityX by some amount every frame, etc, etc

well what about collision?

1 Like