How can I make the camera return to the beginning of the terrain when it reaches the end?

Posted by wbaccari on Game Development See other posts from Game Development or by wbaccari
Published on 2011-11-24T12:50:01Z Indexed on 2011/11/24 18:21 UTC
Read the original article Hit count: 301

How can I make the camera return to the beginning of the terrain when it reaches the end?

I tried using the ICameraSceneNode*->setPosition().

if (camera->getPosition().X>1200.f)
    camera->setPosition(vector3df(1.f,1550.f,camera->getPosition().Z));
if (camera->getPosition().X<0.f)
    camera->setPosition(vector3df(1199.f,1550.f,camera->getPosition().Z));
if (camera->getPosition().Z>1200.f)
    camera->setPosition(vector3df(camera->getPosition().X,1550.f,1.f));
if (camera->getPosition().Z<0.f)
    camera->setPosition(vector3df(camera->getPosition().X,1550.f,1199.f));

It seems to work fine with a flat terrain (one shade of grey in heightmap) but it starts to produce a strange behavior as soon as i try to add some hills.

Edit: The setPosition() call seems to perform a translation of the camera toward the new position, therefore the camera stops at the first obstacle it encounters on its way.

© Game Development or respective owner

Related posts about programming

Related posts about graphics