I recently started with Irrlicht and enjoy it alot so far. But right now Im pretty much stuck, trying to set up a Camera that basically works like in most Hack n Slay Games (Diablo II for example): While the Camera follows the Position of the PlayerCharacter, it does NOT rotate with the PlayerCharacter, but keeps its rotation and offset relative to the playercharacter.
I hope you know what I try to describe, if you dont, please let me know!
So I came up with the following Code, which should do: Create an Empty Node with fixed rotation. Make the CameraNode the Child of the Non-Rotating EmptyNode. Load a MeshNode and make it a child of the EmptyNode, so the Parent of Camera and Mesh are the same. This should result in both moving in exact the same way once the EmptyNode is moved, right? But it doesnt really work: Moving the Empty Node on the x-axis actually makes either the camera or the model rotate in some weird angle around the other, before making the model completely disappear from the cams view.
(Shortening the code, since the full programm uses a rather large but pretty foolproof structure)
Code: Select all
//Declarations
IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;
IGUIEnvironment* guienv;
//Cam and Node
ISceneNode* playerPositionNode; //THIS is basically gonna be the parent to Model and Cam.
ICameraSceneNode *cam;
int main() {
//Setup Device
device = createDevice(video::EDT_OPENGL, dimension2d<u32>(1920, 1080), 32, true, false, true, &receiver);
//Setup Window
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
//Setup PlayerPositionNode
playerPositionNode = smgr->addEmptySceneNode();
//Add Camera
playerPositionNode->addChild(smgr->addCameraSceneNode(0, vector3df(0, 50, -40), vector3df(0, -30, 0)));
//Loading Model
IAnimatedMesh* mesh = smgr->getMesh(path + ".md2");
playerPositionNode->addChild(node = smgr->addAnimatedMeshSceneNode(mesh)); //THIS line is probably important?
//Setting Textures and Animations
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture(0, driver->getTexture(path + ".bmp"));
irr::core::vector3df tempvec(0, 0, 0);
node->setPosition(tempvec);
}
while(true)
{
input();
update();
}
}
irr::f32 x;
void update() {
playerPositionNode->setPosition(irr::core::vector3df(0+x, 0, 0));
}
void input(){
x++;
}