Jump to content
  • Advertisement
Sign in to follow this  
andfol

Player movement.

This topic is 2323 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

Hi,

I have drawn a player with OpenGL and want to put keyboard movement on it. I will be using the GetKeyState() function.
So far I have a move method in my player class.

void CPlayer::move(float x,float y,float z)
{
m_xPos += x;
m_yPos += y;
m_zPos += z;
}

the m_xPos varianles are member variables intialised in a constructor and passed into a translate function in my drawPlayer function, move will update the position of the player.

To manage the key presses I have a PlayerKeys function in main which calls move.

void PlayerKeys(){

if (GetKeyState(VK_UP))
{
g_Player1.move(0.0f, 100.0f, 0.0f);
}

else if(GetKeyState(VK_UP)>0)
{

}
}

The problem is when I call this method in my main loop in main I get an error message identifier not found. I would also be grateful if any one has suggestions for how best to implement my PlayerKeys function as I don't think it is quite right at the moment.

Share this post


Link to post
Share on other sites
Advertisement
Which identifier is not found, is it GetKeyState or PlayerKeys?

Is the PlayerKeys function declared before, after or inside the main function?

Share this post


Link to post
Share on other sites
Hi Pulpfist,

Fixed the identifier problem, like an idiot didn't declare in main.h, I am still trying to write the PlayerKeys function if you have any suggestions would be grateful. Its the same as above just added more keys.

Thanks.

Share this post


Link to post
Share on other sites
Sorry just to add when I run the application pressing any key makes my player disappear.

Share this post


Link to post
Share on other sites

Sorry just to add when I run the application pressing any key makes my player disappear.

that probably means he is moving :) try setting the move amount to 5 or so...

Share this post


Link to post
Share on other sites
Hi,

I'm not all that into OpenGL but if you provide more information and code maybe someone can spot the problem

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!