3rd Person view
Posted: Tue Jun 21, 2005 5:57 pm
Can someone please show me how to add/use a 3rd person camera view on a character?
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
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));