Jump to content
  • Advertisement
Sign in to follow this  

Camera + Player Direction Problem

This topic is 3269 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 gamedev friends, I'm new to 3D game development, so far loving it. Now, got a problem keeping Player's face direction in the same direction as I move... Starting point is fine, but when the camera is turned using Mouse player is facing in different ways while moving. I'm using CCamera, the loaded player's x,z are set to "Camera.mView.x" and "Camera.mView.z" to keep the player in the middle of camera. Currently the rotation of player's Y takes place manually when moving VK_ arrow buttons (0, 90, 180, 270). I want to be able to update player's facing direction automatically to face where camera is currently looking when Arrow keys are used. I've searched to fix this issue past 2-3 days without giving up, but no luck because non of those ideas/logics work with mine.. so I decided to post it here. I'd really appreciate if you cud give me a hand on this one. Thanks in advance!

Share this post

Link to post
Share on other sites
I didn't understand you clearly, but if you want to rotate the camera with the head, you have to know that in openGL the objects are transformed not the camera:

So you have to apply the inverse matrix of the camera matrix.

Simply put: to rotate the camera right, you have to turn the 'world' left instead.

Or try using gluLookAt

I hope that helps.

Share this post

Link to post
Share on other sites
thanks for the reply szecs.

Ok, I'm able to rotate the camera right or left (360*) by counting the angle from the mouse x,z.

//from the CCamera class used in Mouse_Move function..

Yes, I'm using gluLookAt function.

//camera control
gluLookAt(CCamera.mPos.x, CCamera.mPos.y, CCamera.mPos.z,
CCamera.mView.x, CCamera.mView.y, CCamera.mView.z,
CCamera.mUp.x, CCamera.mUp.y, CCamera.mUp.z);

However, I want to know how to turn my loaded model's face automatically where the camera is looking at when keyboard arrow buttons are pressed.

I wonder how to calculate the camera's view to apply that to player's view, for example: when the camera is turned to North, and when the Arrow key (VK_UP) is pressed Player shouldn't be looking at South or West. He should turn from Old_Pos to New_Pos and look at the direction of where Camera is facing.

You said I have to apply the inverse matrix of the camera matrix. How to do that? :\

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!