Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Movement by time

Author
Message
KurtM
10
Years of Service
User Offline
Joined: 8th Jan 2014
Location: United States
Posted: 24th Mar 2014 21:42
Hi all, I am trying to implement a movement by time concept vs moving x amount every tick. The end goal is to pass in a function move sprite x, to location x, from location q, you started moving at time n, you will end there are time z.

I am so close, but there appears to be an error in my math somewhere, the sprite gets close to it's destination but always overshoots by one (x or y) and undershoots the other. Please let me know if you a better way of doing this

Calling my function:


Distance Function:


Movement Function:
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Mar 2014 14:05 Edited at: 25th Mar 2014 23:26
its very easy, you have a time step, means a time.
if you want move 100 units in 1.0 seconds its a=a+100.0 *1.0
if you want move 100 units in 0.5 seconds its a=a+100.0 *0.5

at 60 fps the time step is (1.0/60.0) = 0.0166666666666667 s = 16 ms
60x in loop you move 100 units.
a=a+100.0*0.0166666666666667

u can use GetFrameTime() for it.

moving 100 units in one second in one big step as an example 10 seconds is similar and also linear.
a=a+100.0 *10.0

for your solution u need, you can convert formulas.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
budokaiman
FPSC Tool Maker
14
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 25th Mar 2014 21:08 Edited at: 25th Mar 2014 21:08
Quote: "if you want move 100 units in 0.5 seconds its a=a+100.0 *0.5"

This would actually move slower rather than faster for smaller values, what you would actually want is: a = a + units * ( deltaTime / totalTime ).


"Giraffe is soft, Gorilla is hard." - Phaelax
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Mar 2014 21:44
This is how I do movement and everything else time based:



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Mar 2014 22:08 Edited at: 25th Mar 2014 22:10
@budokaiman
means based on one second because fps is always >0 and <1.0
a = a + units * ( deltaTime / 1.0 )
a = a + units * deltaTime
this is in a game loop.
Digital Awakening used the same in his example.

if you want rotate something its similar.
90° in one second u can use a=a+90.0 / 60.0 (FPS)

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 25th Mar 2014 22:41
To expand on what Markus and DA posted.

Speed is how far something should travel in 1 second
getframeTime() is how long the last frame took to run

So the distance travelled in one frame is;

Speed * getframeTime()

it really is that simple.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Mar 2014 23:46
i made a example moving from actual pos. to next pos. in time x.


AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
budokaiman
FPSC Tool Maker
14
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 26th Mar 2014 11:56
@Markus: I misunderstood what you initially meant, but seeing the edit to your post, I see what you mean now.


"Giraffe is soft, Gorilla is hard." - Phaelax

Login to post a reply

Server time is: 2024-05-05 08:31:00
Your offset time is: 2024-05-05 08:31:00