# 3rd Person Model Rotation Problem.

This topic is 3762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I created a 3ds model in my game where its a 3rd person model I want to use to play around with. My question is how can I make sure the model is facing the correct direction and move it slowly so its not moving the speed of light to the correct position when the camera rotates and insure the model's front faces away from the camera so it will aim where the camera aims. Kinda how Gears Of War 3rd Person Camera works. What I Have Set Up: Init Camera Starting At Cam.xView = 0.00000 Cam.ZView = 0.00000 Rotation Of The Model I have Set To Faced Away From The Camera When It Loads Up When The Game Runs
Angel    x     y     z
90.0f, -1.0f, 0.0f ,0.0f
90.0f, 0.0f, 0.0f ,-1.0f


Win32/C++ Project VS2005 STD OpenGL [Edited by - ajm113 on July 18, 2008 8:27:55 PM]

##### Share on other sites
I wrote some equations for this sort of thing a few weeks back... I'll post them up :) I'm not sure that they're exactly what you're looking for, but hopefully they'll help!

NOTE: You'll need to make a player struct for this to work - if you don't want to, or already have, the xPos and zPos are the floats that determine the player's location. yRot is the players Y rotation...

Moving Forward:
          //Move Forward          float camX = GetCamXPos();          float camZ = GetCamZPos();                    float X,Z;          //Play about with the 0.1f - different scaled engines would need different speeds.          X = 0.1f*sin(degrad(Player.yRot));          camX += X;          Player.xPos += X;          Z = 0.1f*cos(degrad(Player.yRot));          Player.zPos += Z;          camZ += Z;                   SetCameraPos(camX, GetCamYPos(), camZ);//Again, the 0.5f is the player's height... depending on the scale of your game, change this.          SetCameraLookAt(Player.xPos, 0.5f, Player.zPos);

Backwards:
          // Move backward          float camX = GetCamXPos();          float camZ = GetCamZPos();                    float X,Z;          X = 0.1f*sin(degrad(Player.yRot));          Player.xPos -= X;          camX -= X;          Z = 0.1f*cos(degrad(Player.yRot));          Player.zPos -= Z;          camX -= Z;                 SetCameraPos(camX, GetCamYPos(), camZ);          SetCameraLookAt(Player.xPos, 0.5f, Player.zPos);

Turn Left
          // Turn left          float camZ = GetCamZPos();          float camX = GetCamXPos();          float playZ = Player.zPos;          float playX = Player.xPos;                    //Turn the player.          Player.yRot -= 1;                    //The 2 is the player's distance from the camera... again, scale it.          camX = 2*sin(degrad(Player.yRot));          camZ = 2*cos(degrad(Player.yRot));                    SetCameraPos(camX, GetCamYPos(), camZ);          SetCameraLookAt(playX, 0.5f, playZ);

Turn Right
          //Turn Right          float camZ = GetCamZPos();          float camX = GetCamXPos();          float playZ = Player.zPos;          float playX = Player.xPos;                    Player.yRot += 1;                    camX = 2*sin(degrad(Player.yRot));          camZ = 2*cos(degrad(Player.yRot));                    SetCameraPos(camX, GetCamYPos(), camZ);          SetCameraLookAt(Player.xPos, 0.5f, Player.zPos);

Hope that helps! Good luck!

##### Share on other sites
Oh, wow I just checked back here just double checking any replies until giving up on this thread! Thanks a lot man I appreciate your effort into helping me!

1. 1
Rutin
65
2. 2
3. 3
4. 4
5. 5

• 16
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633415
• Total Posts
3011766
• ### Who's Online (See full list)

There are no registered users currently online

×