Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
826 views
in Technique[技术] by (71.8m points)

game physics - Minimum movement per frame

When it comes to calculating movement in a game engine, each frame I update the position of the player, based on his speed. If I try to be realistic in my calculations, I end up with a displacement per frame that is so small that movement overall doesn't occur or, when accelerating, occurs only discontinuously.
Here's an example:

frame rate = 60 fps

window height = 600 px

scale = 10px = 1 m

speed = 2 m/s = 0.03... m/frame (Let's assume the player is free falling and accelerating under gravity of 9.8 m/s)

With this data, the minimum displacement is 1 pixel = 0.1m, so the end result is no movement for a lot of frames. If the speed is constant, no movement occurs at all.
For now, I used a multiplicative factor to scale my calculations up, but is there a better approach to deal with this?
Basically, my question is: how should I handle (small) fractions of movement in a consistent and realistic way?

EDIT: The solution should be to always use floats(doubles) for every physical variable including object position in space and convert to integer pixel coordinate only as a last step when it's time to render. This way in the physical model everything works, even fine movement. Mauro


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...