in the beginers forum I had the idea for a simple steering system by only using Irrlicht possibilities...
After this I created a simple path finding system by using waypoints !!!
The source is a little bit to big for posting here, so I made a download avilable...
demo + source: SimpleSteering.zip
And this is the really simple steering demo !!!
There is one enemy that always faces the player (camera) and moves straight to him...
Code: Select all
// !!! define here your Irrlicht media directory !!!
#define irrMediaDir "C:/CodeBlocks/AB-AddOn/Media/Irrlicht"
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
int main(){
IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(800, 600));
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
// create a ground (just for optic)
ISceneNode* ground = smgr->addTestSceneNode(10);
ground->setScale(vector3df(500, 1, 500));
ground->setMaterialTexture( 0, driver->getTexture(irrMediaDir"/wall.bmp") );
ground->setMaterialFlag(EMF_LIGHTING, false);
// create enemy
ICameraSceneNode* camEnemy = smgr->addCameraSceneNodeFPS();
camEnemy->setPosition(vector3df(0, 45, 0));
IAnimatedMesh* mesh = smgr->getMesh(irrMediaDir"/faerie.md2");
IAnimatedMeshSceneNode* nodeEnemy = smgr->addAnimatedMeshSceneNode(mesh, camEnemy);
nodeEnemy->setMaterialTexture( 0, driver->getTexture(irrMediaDir"/faerie2.bmp") );
nodeEnemy->setMaterialFlag(EMF_LIGHTING, false);
nodeEnemy->setMD2Animation(EMAT_RUN);
// rotation offset for faerie, because she's looking to the side
nodeEnemy->setRotation(vector3df(0, -90, 0));
// position offset to get faerie to the ground
nodeEnemy->setPosition(vector3df(0, -16, 0));
// create player camera
ICameraSceneNode* camPlayer = smgr->addCameraSceneNodeFPS(0, 100.0f, 500.0f, -1, 0, 0, true);
camPlayer->setPosition(vector3df(0, 45, -150));
device->getCursorControl()->setVisible(false);
while(device->run()){
driver->beginScene(true, true, SColor(255,100,100,150));
smgr->drawAll();
driver->endScene();
// update enemy rotation
camEnemy->setTarget(camPlayer->getPosition());
camEnemy->updateAbsolutePosition();
// move enemy
line3d<f32> line;
line.start = camEnemy->getPosition();
line.end = line.start + (camPlayer->getPosition() - line.start).normalize() * 0.1;
camEnemy->setPosition(line.end);
}
device->drop();
return 0;
}