I want the character to reverse directions when it crosses a certain distance in the x direction, but that is happening only for the positive direction.
I'm probably doing a stupid mistke, but please look at the code.
Code: Select all
#include<irrlicht/irrlicht.h>
using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
using namespace io;
int main()
{
IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2d<u32>(800,600),32,false,false,false,0);
if(!device)return 1;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IAnimatedMesh* m = smgr->getMesh("../../media/sydney.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(m);
if(node)
{
node->setMaterialFlag(EMF_LIGHTING,false);
node->setMaterialTexture(0,driver->getTexture("../../media/sydney.bmp"));
node->setMD2Animation(scene::EMAT_RUN);
}
smgr->addCameraSceneNode(0,vector3df(0,0,-500),vector3df(0,0,0));
double v = -.0001, x = 0.0;
double then = device->getTimer()->getTime();
while(device->run())
{
driver->beginScene(true,true,SColor(255,255,255,255));
double now = device->getTimer()->getTime();
double dt = then - now;
x+=v*dt;
node->setPosition(vector3df(x,0,0));
if(x>100||x<(-100))
{
v=-v;
node->setRotation(vector3df(0,180,0));
}
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}