3rd person camera.
3rd person camera.
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
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.
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:
As you change your swivel angle, one way you can change the camera's position relative to the parent node is like this:
These are just tiny snippets. You obviously need to play around a bit to get the exact effect you're after.
Code: Select all
irr::scene::ICameraSceneNode *swivelCamera = smgr->addCameraSceneNode( objectNode, irr::core::vector3df( 0, 1, -1), objectNode->getAbsolutePosition(), 0 );
Code: Select all
swivelCamera->setTarget( objectNode->getAbsolutePosition() );
Code: Select all
irr::core::vector3df swivelCameraPosition = swivelCamera->getAbsolutePosition();
swivelCameraPosition.rotateXZBy( swivelAngleChange, objectNode->getAbsolutePosition() );
swivelCamera->setPosition( swivelCameraPosition - objectNode->getAbsolutePosition() );