Jump to content
  • Advertisement
Sign in to follow this  
ajm113

3rd Person Model Rotation Problem.

This topic is 3614 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 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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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!

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!