Jump to content

  • Log In with Google      Sign In   
  • Create Account


Player movement.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 andfol   Members   -  Reputation: 101

Like
0Likes
Like

Posted 09 March 2012 - 07:32 AM

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.

Sponsor:

#2 pulpfist   Members   -  Reputation: 528

Like
0Likes
Like

Posted 09 March 2012 - 08:21 AM

Which identifier is not found, is it GetKeyState or PlayerKeys?

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

#3 andfol   Members   -  Reputation: 101

Like
0Likes
Like

Posted 09 March 2012 - 11:10 AM

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.

#4 andfol   Members   -  Reputation: 101

Like
0Likes
Like

Posted 09 March 2012 - 11:13 AM

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

#5 Ghosrath   Members   -  Reputation: 121

Like
0Likes
Like

Posted 09 March 2012 - 11:44 AM

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...

#6 andfol   Members   -  Reputation: 101

Like
0Likes
Like

Posted 09 March 2012 - 12:11 PM

Thanks Ghosrath it worked!!

#7 andfol   Members   -  Reputation: 101

Like
-1Likes
Like

Posted 09 March 2012 - 12:18 PM

It worked but after a while my animated legs and arms do strange things. Any ideas?

#8 pulpfist   Members   -  Reputation: 528

Like
0Likes
Like

Posted 09 March 2012 - 03:30 PM

Hi,

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS