## Slow-motion math

• 254 Views
• 3 Replies
Arkuni
Arkuni
• Member since: Mar. 14, 2005
• Offline.
Forum Stats
Member
Level 20
Blank Slate
Slow-motion math 2009-07-19 12:04:19

I'm building a platforming engine where you can slow down time. Pretty easy, until I reached the jumping part.

If space is held down, it'll slow down time down to 10% as seen below.

``````if(key_space){
game_speed_multiplier -= 0.05;
if(game_speed_multiplier < 0.1){
game_speed_multiplier = 0.1;
}
}else{
game_speed_multiplier += 0.05;
if(game_speed_multiplier > 1){
game_speed_multiplier = 1;
}
}``````

This is the jumping physic.

``````if(player_status_jump){
mc_player.y -= player_movement_y * game_speed_multiplier;
player_movement_y /= 1 + (0.5 * game_speed_multiplier);
if(player_movement_y < 1){
player_movement_y = 0;
player_status_jump = false;
}
}``````

player_movement_y decides how much mc_player should move on the Y axis. Normally I would just divide player_movement_y by 1.5 untill it drops below 1 and then just set it to 0.

What I got now, works a little bit. But player_movement_y decreases faster than in regular motion, so it is still not 100% complete.

Anyone who can math this out out?

Okay, okay... something funny... something funny.... hmmm.... which quote am I most likely to get away with as my own?... I KNOW!!! "I eat my own shit!" - The local homeless

GustTheASGuy
GustTheASGuy
• Member since: Nov. 2, 2005
• Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Slow-motion math 2009-07-19 12:53:06

Use separate variables for the velocity of the object. So that your code only updates the actual X and Y position in one place. Then you can easily apply the slowdown there.

Arkuni
Arkuni
• Member since: Mar. 14, 2005
• Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to Slow-motion math 2009-07-19 14:45:20

Got an example?

Okay, okay... something funny... something funny.... hmmm.... which quote am I most likely to get away with as my own?... I KNOW!!! "I eat my own shit!" - The local homeless

GustTheASGuy
GustTheASGuy
• Member since: Nov. 2, 2005
• Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Slow-motion math 2009-07-19 15:08:15

``````if (key.right) vx += fH;
if (key.left)  vx -= fH;

if (standing && key.jump) vy = fJump;
if (jumping) vy -= fFall;

_x += vx * dt; _y += vy * dt;``````