Sign in to follow this  
HalcyonX

Player control: position, velocity, or acceleration?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this