• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Legacy GM bug with movement speed with slowmo, rounding?

silverfrost

Member
Hi. I'm decided to make slowmo in my game. I created an object that moves up for 2 seconds (or 4 seconds in slowmo) with increasing accelereation over time. While object moves it should travel same distance in normal and slowmo time.

In create event I have:
Code:
//time handle
global.time_speed = 1; //time multiplier 0.5 - x2 slower, 0.25 - x4 slower etc.
global.time_fps = room_speed / global.time_speed; //frames needed to draw 1 second of game

//start params
speed_base = 10; //pixels per second
speed_acceleration = 4; //pixel per second
speed_base_current = 0; //current obj speed
speed_acceleration_current = 0; //current obj acceleration
travel_distance = 0; //obj travel distance
move_time = 2; //in seconds
move_counter = 0;
move_current = 0; //current distance to move
My default room_speed is 30. So when I slow time x2 variables are:
Code:
global.time_speed = 0.5;
global.time_fps = 60;
And in step event I have:
Code:
//change animation speed according to current time scale
speed_base_current = speed_base / global.time_fps; //divided by 30 for normal time or by 60 for slowed time
speed_acceleration_current += speed_acceleration / global.time_fps; //divided by 30 for normal time or by 60 for slowed time
move_current = speed_base_current + speed_acceleration_current;
//move object
travel_distance += move_current;
y -= move_current;
//move counter
if (move_counter <= move_time) move_counter += 1 / global.time_fps;
else instance_destroy();
The problem is that object in normal time & in slowmo travels different distance while it should travel the same distance, because in slowmo it's move speed decreased according to more frames. In normal time it travels about 281 pixel and in slowmo about 520 (measured on destroy by travel_distance).

I also tried to use 1/10 second interval in alarm to increase speed, insted of doing it every frame, but have also different travel distances.

What is wrong? Is this rounding problem? How this can be fixed?

Thanks in advance.
 

silverfrost

Member
Small update.

Using excel tables with per frame values calculated for each variable I was able to figure it out that I forgot to multiply each current acceleration values with current time_speed var. Doing that gives me somewhat close results between different slowmo modes. Travel distance not equal again, but it gives difference about 5%, so I think it won't be noticeable. But still wondering if anyone have better solution?

Changes in step event:
Code:
speed_acceleration_current += (speed_acceleration * global.time_speed) / global.time_fps;
 

Simon Gust

Member
Small update.
Using excel tables with per frame values calculated for each variable I was able to figure it out that I forgot to multiply each current acceleration values with current time_speed var. Doing that gives me somewhat close results between different slowmo modes. Travel distance not equal again, but it gives difference about 5%, so I think it won't be noticeable. But still wondering if anyone have better solution?
Hi,
You could always cheat and only update the step every 2 Frames, it will just look like 30fps then. How it works:
make a variable (num) and increase it every step by 1
where you have your code write:
Code:
if (num mod 2 == 0)
{
    //all your code
}
num++;
The travel distance has to be cut in half too though.
 

silverfrost

Member
Hi,
You could always cheat and only update the step every 2 Frames, it will just look like 30fps then. How it works:
make a variable (num) and increase it every step by 1
where you have your code write:
Code:
if (num mod 2 == 0)
{
    //all your code
}
num++;
The travel distance has to be cut in half too though.
Thanks, for advice. I'd tried frameskip right after experimenting with room_speed directly. Both ways looks like game just start to expirience some perfomance issues. It's ok, for x2 slow with room_speed=60 by default, but when you set slowmo to x4, or x8, or x16 (about 4 fps) it just looks terrible.

I'd searched forum & googled for any good slowmo solutions, but all I found was this two ways (frameskip/room_speed). So I came up with this solution I'd tried to explain.
 
Top