Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tigra7

Best way to store player position?

This topic is 5574 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 am trying to create a small fps in opengl using c++. I was just wondering what some other people''s oppinions were to store the player position and move it accordingly. Particularly, my problem lies within my method for storing it. I use two functions. One of them is MovePlayer(float x, y, z). Another is CheckForKeyPress(), which looks like this: { if(Keypressed = ''VK_UP'') { MovePlayer(speed.x, y, speed.z); } } Now the problem with this is, when I press Up, it changes the position while I press it, but it resets itself when I release the button. How can I fix this? Thanks for any respones.

Share this post


Link to post
Share on other sites
Advertisement
instead of calling your move function only when a key is pressed, call your move function every frame. As far as when a key is pressed, in the code for that you should set the speed to something higher... maybe Player.xSpeed += 3; or something similar... you might also consider having a direction and magnitude (vector?) member of the player, which describes how far & what direction they''re going to move next frame... and when you press up, generate a vector and add it to the member, which would modify it. then when movePlayer() is called, it will take the vector and move the player in that direction (note, when the vector / speeds are 0, it wont actually move the player...)

Share this post


Link to post
Share on other sites
there''s 2 ways that you can go about storing your location. First use a structure:

TYPEDEF STRUCT coords {
float x,y,z;
}

Or you can store them array. A problem with this is that you have to remember which value your storing in each element of the array. To do this use:

float coords[3] = {0.0f, 0.0f, 0.0f);

This should work if my coding is correct, just a matter of how you put it to use.

Higher Forces

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!