Jump to content
• What is your GameDev Story?

• Advertisement

Public Group

Frame Rate Independant Velocity

This topic is 4967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a simply 3D Pong game, and have come to write the physics for the ball's movement. What I've done of the physics routine so far is:
Public LastPhysicsUpdate As Long

Public Sub DoPhysics()

Dim TimeChange  As Single

TimeChange = (GetTickCount - LastPhysicsUpdate) / 1000

ballPos.X = ballPos.X + ballVelocity.X * TimeChange
ballPos.Y = ballPos.Y + ballVelocity.Y * TimeChange
ballPos.Z = ballPos.Z + ballVelocity.Z * TimeChange

LastPhysicsUpdate = GetTickCount

End Sub


Basically, the velocity is in texels(?) per second and is multiplied by the time since the last physics update and added to the old ball position. I was wondering - is this the way to do it or is there a better method? Degra

Share this post

Share on other sites
Advertisement
Yeah, lock your frame rate. Don't continue if your diff is too small. I think 60fps should be fine, but make it a variable you can play with.

I don't really know VB but this would be the general idea:

Public LastPhysicsUpdate As LongPublic physicsFrameRate As FloatPublic Sub initPhysics()    physicsFrameRate = 1.0f / 60.0fEnd SubPublic Sub DoPhysics()    Dim TimeChange  As Single        TimeChange = (GetTickCount - LastPhysicsUpdate) / 1000    if( TimeChange &gt;= physicsFrameRate){        ballPos.X = ballPos.X + ballVelocity.X * TimeChange        ballPos.Y = ballPos.Y + ballVelocity.Y * TimeChange        ballPos.Z = ballPos.Z + ballVelocity.Z * TimeChange        // This is only updated when we enter the loop        LastPhysicsUpdate = GetTickCount    }        End Sub

Share this post

Share on other sites

• Advertisement
• Advertisement
• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• Popular Now

• 11
• 13
• 9
• 9
• 15
• Advertisement
• Forum Statistics

• Total Topics
634078
• Total Posts
3015370
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!