3rd person camera

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
shadowrider
Posts: 5
Joined: Tue Jan 31, 2006 5:18 pm

3rd person camera

Post by shadowrider »

hi,
i created a class for camera that will attach the camera node to player node.
and i just set the parent of camera is the player, but it seems to be always in front of the player. does anyone know how to position it behind the player?

Code: Select all

class attachCamera
   {
          ICameraSceneNode*  cam;
          vector3df          camOffset;
          ISceneNode*        ScnNode;
      public:
          attachCamera(ISceneNode* SNode,ICameraSceneNode* camera,vector3df offset)
            {
                ScnNode = SNode;
                cam = camera;
                camOffset = offset;
		          cam->setParent(ScnNode);
		          cam->setPosition(offset); 
		          cam->setRotation(vector3df(0,180,0));
            }    
           ~attachCamera() {}
           void updateCamera()
             {
                 vector3df CamPos = ScnNode->getPosition();
                 CamPos.Y += camOffset.Y;
                 cam->setTarget(CamPos);   
             }      
   };            
thanks
RadBrad

Post by RadBrad »

You need to offset the camera behind the player after you've attached it onto him.

Code: Select all

class attachCamera 
   { 
          ICameraSceneNode*  cam; 
          vector3df          camOffset; 
          ISceneNode*        ScnNode; 
      public: 
          attachCamera(ISceneNode* SNode,ICameraSceneNode* camera,vector3df offset) 
            { 
                ScnNode = SNode; 
                cam = camera; 
                camOffset = offset; 
                cam->setParent(ScnNode); 
                cam->setPosition(offset); 
                cam->setRotation(vector3df(0,180,0)); 
            }    
           ~attachCamera() {} 
           void updateCamera() 
             { 
                 vector3df CamPos = ScnNode->getPosition(); 
                 CamPos.Y += camOffset.Y; 
                 cam->setTarget(CamPos);    
                 cam->setPosition(vector3df(x,x,x)); // <<< here
             }      
   };      
Change the vector3df(x,x,x) to the offset where the camera is going to be behind the player. I don't know if this will work but give it shot... if not try loading the characters position (x, y, z coordinates) into variables and have the cam offset the y variable with the addition of say 50 and x as say 50. This will place the camera onto the character but behind him.
Guest

Post by Guest »

thanks.
it works. it does the trick, but here's the weird part. depending on the model, the rotation will be different.
like for example, the model from http://s-fonline.com/webhosting/dhenton9000/models.php works fine without the code change, and now with the change, it's facing the wrong way.

but with another model i made, with the code change, it'll face the right way.

is there any certain way when exporting the model from 3ds that will affect the axis/normals?
if i could know how they export it from that website, then everything will be easier.

thanks
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

You can add an offset into rotation angle. This offset depends on model orientation (may be 0, 90, 180 or 270°). I posted a third person camera into beginer forum, hop it could help.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
shadowrider
Posts: 5
Joined: Tue Jan 31, 2006 5:18 pm

Post by shadowrider »

xterminhate, this might be a solution. how would i implement it in my code?
i just need to identify what's the current model orientation

thanks
Post Reply