3rd Person view
3rd Person view
Can someone please show me how to add/use a 3rd person camera view on a character?
-
- Posts: 69
- Joined: Wed Mar 30, 2005 8:16 am
- Location: Keerbergen, Belgium
1) use setTarget to set your player as the target the camera is looking at
2) then: use sin,cos stuff to set the height, ...
3) make it so that in the event receiver it can rotate the camera and zoom in/out
4) update the camera location every time the player moves or the camera is rotated (do 1 and 2)
AND CHECK THE FORUM
2) then: use sin,cos stuff to set the height, ...
3) make it so that in the event receiver it can rotate the camera and zoom in/out
4) update the camera location every time the player moves or the camera is rotated (do 1 and 2)
AND CHECK THE FORUM
-
- Posts: 69
- Joined: Wed Mar 30, 2005 8:16 am
- Location: Keerbergen, Belgium
here is some code:
CameraDistance is a float which shoul be adjustable by scrolling (im not going to explain that part).
All the rest should be obvious.
You can adjust a few things (the rotation and stuff) for example: the camera is now facing the feet of the player, you can adjust it by doing:
camera->setTarget(vector3df(playerpos.X,playerpos.Y+20,playerpos.Z));
Code: Select all
position2d<f32> RelMousePos = device->getCursorControl()->getRelativePosition();
if(RelMousePos.X >= 0.8)
{
float rotation = (RelMousePos.X-0.8)*10;
fAngleX += rotation;
if(fAngleX >= 360)
fAngleX = 0;
}
if(RelMousePos.X <= 0.2)
{
float rotation = (0.2-RelMousePos.X)*10;
fAngleX -= rotation;
if(fAngleX <= 0)
fAngleX = 360;
}
if(RelMousePos.Y >= 0.8)
{
float rotation = (RelMousePos.Y-0.8)*10;
fAngleY -= rotation;
if(fAngleY <= 20)
fAngleY = 20;
}
if(RelMousePos.Y <= 0.2)
{
float rotation = (0.2-RelMousePos.Y)*10;
fAngleY += rotation;
if(fAngleY >= 75)
fAngleY = 75;
}
vector3df CameraPos;
ICameraSceneNode* camera = smgr->getActiveCamera();
float fXZDistance = CameraDistance*cos(PI*(fAngleY/180));
CameraPos.Y = playerpos.Y + CameraDistance*sin(PI*(fAngleY/180));
CameraPos.X = playerpos.X + cos(PI*(fAngleX/180))*fXZDistance;
CameraPos.Z = playerpos.Z + sin(PI*(fAngleX/180))*fXZDistance;
camera->setPosition(CameraPos);
camera->setTarget(vector3df(playerpos.X,playerpos.Y,playerpos.Z));
All the rest should be obvious.
You can adjust a few things (the rotation and stuff) for example: the camera is now facing the feet of the player, you can adjust it by doing:
camera->setTarget(vector3df(playerpos.X,playerpos.Y+20,playerpos.Z));