Player control: position, velocity, or acceleration?

Started by
2 comments, last by ursus 18 years, 7 months ago
Im making a game that involves the player controlling a human character, and am faced with a problem im sure everyone has encountered. When the player hits the "up" key, the character is supposed to move forward. At first, I made it so that if the "up" key is held down, then at every cycle of the game loop, the character's position is moved forward by some amount. It worked fine until i tried to implement physics. For physics, i need velocity and acceleration. When a force is applied, acceleration changes. At every cycle, i update velocity based on acceleration, then update position based on velocity. This, then, is a problem, because the change in position due to the "up" key is not reflected in the velocity. I then thought about having the "up" key adjust velocity, but then that would cause a similar problem between velocity and acceleration. If i make it adjust acceleration, it would involve some weird logic. Anyone know of a good solution? What is the method used in most games? Thanks.
Advertisement
I believe this article holds the sollution to your problem:

Robert Dunlop - implementing steady montion

and here is a link to my project, so you can take a look how i did it.
oh heh, now it looks so simple. Makes me wonder why i didnt think of doing it that way. Thanks a bunch!
well, the idea is trully simple. but i advice to practice caution. it took me quite some time to get things work the way they should. what's more, i bet you're going to get some phisics and maths books soon to refresh your primary school knowledge. this happened to me ;-)

anyways, good luck with your porject.

This topic is closed to new replies.

Advertisement