The Daily Click ::. Forums ::. Non-Klik Coding Help ::. Slowing down time
 

Post Reply  Post Oekaki 
 

Posted By Message

CakeSpear



Registered
  28/01/2004
Points
  112
9th May, 2012 at 09/05/2012 12:16:20 -

Hi
Ive been struggeling for the longest time now with how to correctly slow down time in my game.
Ive tried to keep it simple and get it to work correctly and precisely in a simple scenario 'a falling rock affected by gravity'

...
Ive been following an example wich states that this is how you do it:

ADD GRAVITY
Set SpeedY_ to: SpeedY_ + GravityStrength_ * TimeRatio_

MOVE PLAYER
Set Ypossition to: Ypossition + SpeedY_ * TrimeRatio_

However, doing the math on this produces inaccurate results.
Ive also tried few other methods and solutions, but i cant get it to work and i cant seem to wrap my head around it.

What i want to do is simple enough:
I want a falling Rock affected by gravity, to move the same distance accross 2 frames at 100% speed, as it does across 4 frames at 50% speed.

...
I know this is not an easy question.
Could someone pleace help me slow down time?

 
n/a

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  1078

Candle
9th May, 2012 at 09/05/2012 12:29:03 -

I have not tried this myself. But I am always leery of trying to make MMF2 do things with anything other than a complete integer and I avoid most decimals. One thing I would suggest as a possible solution is to create the game with its native state as the slow speed, and then multiply everything from there.

In other words, the regular pace for the game is at 50%, but unless the "slow down time" feature is activated, the game always works at double speed. the player won't know the difference, and when you want to switch the game to the slower speed it would work fine.

At least theoretically, this works in my head. Good luck to you.

 
n/a

CakeSpear



Registered
  28/01/2004
Points
  112
9th May, 2012 at 09/05/2012 12:46:56 -

This much i do understand:

...
AT 100% SPEED
( TimerRatio = 1 )

FRAME1
Gravity = Gravity + 1 * 1 = 1

FRAME2
Gravity = Gravity + 1 * 1 = 2


AT 50% SPEED
( TimerRatio = 0.5 )

FRAME1
Gravity = Gravity + 1 * 0.5 = 0.5

FRAME2
Gravity = Gravity + 1 * 0.5 = 1

FRAME3
Gravity = Gravity + 1 * 0.5 = 1.5

FRAME4
Gravity = Gravity + 1 * 0.5 = 2

...
So this looks correct, at 100% speed Gravity goes from 0 - 2 across 2 frames, and at 50% speed Gravity goes from 0 - 2 across 4 frames.
Sounds logical and correct right?

But where do i go from here, whats the next step, how do i get my Rock to move correctly?

 
n/a

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  1078

Candle
9th May, 2012 at 09/05/2012 13:42:29 -

I suggest trying my theory and see if it works for you. Let me modify your coding as follows:

///

AT 100% SPEED
( TimerRatio = 2 )

FRAME1
Gravity = Gravity + 1 * 2 = 2

FRAME2
Gravity = Gravity + 1 * 2 = 4


AT 50% SPEED
( TimerRatio = 0.5 )

FRAME1
Gravity = Gravity + 1 * 1 = 1

FRAME2
Gravity = Gravity + 1 * 1 = 2

FRAME3
Gravity = Gravity + 1 * 1 = 3

FRAME4
Gravity = Gravity + 1 * 1 = 4

///

 
n/a

Duncan

Thelonious Dunc

Registered
  18/05/2002
Points
  552

VIP Member
9th May, 2012 at 09/05/2012 14:15:08 -

Are you trying to manipulate the object's Y position directly? You can't move something by 0.5 pixels, so you can't treat coordinates as floats. Just use an alterable value for all your calculations and then, after the rest of your movement events, set the object's x and y to the appropriate values. Sorry if I misunderstood

 
n/a

nim



Registered
  17/05/2002
Points
  7233
9th May, 2012 at 09/05/2012 15:47:52 -

Here's a good article about slowing down objects to create that effect.
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=110271

 
//

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  1078

Candle
9th May, 2012 at 09/05/2012 17:01:34 -

That's a fantastic article...! I have yet to check out the example but at first glance, it looks like it would solve all of CakeSpear's challenges.

 
n/a

CakeSpear



Registered
  28/01/2004
Points
  112
9th May, 2012 at 09/05/2012 23:28:36 -

The method i am having troubble with in this thread, is the exact same method explained in that article. I am 100& sure of that, because i directly learnt this method from that article.

 
n/a

CakeSpear



Registered
  28/01/2004
Points
  112
9th May, 2012 at 09/05/2012 23:38:27 -

OK s-m-r, lets try your suggestion.

AT 100% SPEED
( TimerRatio = 2 )

FRAME1
Gravity = Gravity + 1 * 2 = 2
Object Moves: 2 pixels

FRAME2
Gravity = Gravity + 1 * 2 = 4
Object Moves: 4 pixels

Object TOTAL MOVE = 2 + 4 = 6 pixels



AT 50% SPEED
( TimerRatio = 1 )

FRAME1
Gravity = Gravity + 1 * 1 = 1
Object Moves: 1 pixels

FRAME2
Gravity = Gravity + 1 * 1 = 2
Object Moves: 2 pixels

FRAME3
Gravity = Gravity + 1 * 1 = 3
Object Moves: 3 pixels

FRAME4
Gravity = Gravity + 1 * 1 = 4
Object Moves: 4 pixels

Object TOTAL MOVE = 1 + 2 + 3 + 4 = 10 pixels

...
According to the results, at 50% speed the Object actually moves FASTER than it does at 100% speed.

Edited by CakeSpear

 
n/a

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  1078

Candle
10th May, 2012 at 10/05/2012 13:45:59 -

Sorry my solution doesn't work. Maybe contact Deadman Dines and see if he has a solution for you, to follow up his CT Forum article.

Maybe it's in the way he explains it, I dunno. Have you tried using his example and tooling around a little bit?

 
n/a

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
10th May, 2012 at 10/05/2012 14:00:19 -

If it's any consolation, I can't get the Maths to work either, and I wrote the article

All I know is it works... somehow, by some evil trickery... it works
If you plug the formulae into an object in MMF, it'll jump and fall consistently across different time ratios. So I suspect we're just not testing/understanding the arithmetic properly.

Edited by DeadmanDines

 
191 / 9999 * 7 + 191 * 7

CakeSpear



Registered
  28/01/2004
Points
  112
13th May, 2012 at 13/05/2012 00:35:21 -

Hey Dines
So you wrote the Article, but did you also make the example?

 
n/a

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
13th May, 2012 at 13/05/2012 03:05:39 -

If you opened the example and looked at the author you'd see he did.

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
13th May, 2012 at 13/05/2012 18:25:27 -

Yeah, basically I had a problem with getting gravity to work myself, and found the solution that worked for my example was the one I mentioned in the article, which is shown in the examples, namely to apply the ratio on gravity twice - once to account for the fact that gravity is applied more often at slower speeds, and a 2nd time to reduce the on-screen display speed.

The maths do kind of work if you walk through them in excel, but they're still inaccurate over time. In my tests, I start with an upward inertia of -5px per frame. On each frame we apply 1px * time for gravity to arrive at a revised inertia, then apply time again on the total inertia remaining. The figures are close enough if you compare different rates side by side, but even so they do drift apart over time. Thankfully, it doesn't really notice in a game.

The issue behind it is the use of compound percentages - suppose you charge someone 25% of £1000 each year (£250). Your boss decides he'd rather charge them twice a year to improve cash flow. But look at the math:

First six months: 12.5% on 1000 = 125.
Second six months: 12.5% on 1125 = 1265.63.
See that it doesn't add up to the 1250 that it would if you'd applied only one lot of 25% rather than two lots of 12.5%?

I think that's what's happening, in which case I'll need to use a variation on compound interest calculations to sort it. D'oh!

 
191 / 9999 * 7 + 191 * 7

CakeSpear



Registered
  28/01/2004
Points
  112
13th May, 2012 at 13/05/2012 22:47:23 -

Well i am in the process of figuring out an accurate method for slowing down time, specifically a method that 'applies gravity correctly' because this is what is causing the inaccuracy in the first place.

Ill try to convey the basic idea behind this throug an example:
If the timeRatio is 0,25 ( 25% game speed ), gravity should only be 'applied' every 4 frames ( not every single frame, while objects still move every Frame )

 
n/a
   

Post Reply



 



Advertisement

Worth A Click