3rd person camera.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Nosvera2
Posts: 16
Joined: Wed May 28, 2008 3:11 am
Location: Van Buren, Arkansas

3rd person camera.

Post by Nosvera2 »

Being new to irrlicht, I would like to know how to create a camera that can't move in the up/down directions and is fixed at a certain position above and behind an object. I plan on making an interface similar to that of Runescape: with the arrows controling the swivel of the camera around a character and the mouse being free to click on objects. Can anyone refer me to a game like this where I can look at the code? Does anyone know how to do this?
merovingian
Posts: 37
Joined: Thu Feb 28, 2008 4:34 am
Location: Perth, Western Australia

Post by merovingian »

I was a beginner a couple of months ago, and I can tell you this is easy. Add a regular (ie. not FPS) camera to your scene, and assign the node of your object as the parent. The following line adds a camera as a child to your object, one unit above (Y) and one unit behind (Z) the parent object, with the camera looking at the origin of the parent object.

Code: Select all

irr::scene::ICameraSceneNode *swivelCamera = smgr->addCameraSceneNode( objectNode, irr::core::vector3df( 0, 1, -1), objectNode->getAbsolutePosition(), 0 );
Since it is a child of your parent object, it will move when your parent object moves. You will need to keep updating the camera target as the parent object moves:

Code: Select all

swivelCamera->setTarget( objectNode->getAbsolutePosition() );
As you change your swivel angle, one way you can change the camera's position relative to the parent node is like this:

Code: Select all

irr::core::vector3df swivelCameraPosition = swivelCamera->getAbsolutePosition();
swivelCameraPosition.rotateXZBy( swivelAngleChange, objectNode->getAbsolutePosition() );
swivelCamera->setPosition( swivelCameraPosition - objectNode->getAbsolutePosition() );
These are just tiny snippets. You obviously need to play around a bit to get the exact effect you're after.
Post Reply