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.

DarkBASIC Professional Discussion / Delta time and acceleration

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 26th Sep 2004 08:10
I know I should know this, but I could do with some reassurance.....

I have some code that isn't working properly, (objects not moving at the right speed), and there could be a number of reasons why it's not working - I just want to discount this as a cause.

Here goes:

Once you've set up a timer based loop, using something along the lines of ........

starttime=timer()

do

newtime=timer()-starttime
deltatime=newtime-oldtime
oldtime=newtime

loop

..... then I think I'm right in saying that to move an object along the x axis with a velocity v#, you'd say:

x#=x#+(v#*deltatime)

Question is this - how do you then adjust the velocity to make the object accelerate by an amount a#? Is it just

v#=v#+(a#*deltatime) ?


Thanks,

Ric.


The Wendigo
22
Years of Service
User Offline
Joined: 13th Sep 2002
Location: A hole near the base of a tree in the US
Posted: 26th Sep 2004 17:54
Well, physics states that you are very much correct about velocity:

x = x + (v * Time)

And with acceleration, guess what, it's very similar. It's time squared.

x = x + (a * Time^2)

(That might not be the quite right equation. it's been a while since a physics class).

But "Ack!" you say. How does that work with my code?! And probably what I (and most everyone in my phys class was asking) "How the heck do you get time squared?" Well it ends up working out!

As it works, everything must be synced (as you know), and acceleration is no different.

v# = v# + (a# * Time)

Which all put together equals:

v# = v# + (a# * Time)
x# = x# + (v# * Time)

Which boils down to (if my brain is working correctly, I'm tired) YOU ARE ABSOLUTELY RIGHT! Looks like the same code I use for gravity (which is basically an acceleration of velocity in the downward direction )


NOTE: Not sure I understand your delta time system and my mind is fizzled from working on Strata Works right now, but I use a system like this:



Just seems simpler to me and I haven't had probs with it yet, but hey, to each their own.

Good luck on your project!

Current Projects: Verious things right now. Lots of utils for game making. Hopefully something solid soon.

http://www.geocities.com/djpeterson83
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 26th Sep 2004 23:16
Cheers Wendigo - confirmed what I thought ... the bug in my program is somewhere else!!


Login to post a reply

Server time is: 2025-06-03 17:27:35
Your offset time is: 2025-06-03 17:27:35