Collision detection on heightmap terrain

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
tomas.vymazal
Posts: 6
Joined: Mon Aug 07, 2006 3:39 pm
Location: Czech Republic

Collision detection on heightmap terrain

Post by tomas.vymazal »

Hi, I would like to ask, how to make a collision detection with terrain loaded from heightmap. I made this code, but it doesn't work:

Code: Select all

terrain = smgr->addTerrainSceneNode("media\\terrain-heightmap.bmp");

    if (!terrain)
        return false;

    terrain->setScale(vector3df(40.0f, 4.4f, 40));
    terrain->setMaterialFlag(EMF_LIGHTING, false);

    terrain->setMaterialTexture(0, driver->getTexture("media\\terrain-texture.bmp"));
    terrain->setMaterialTexture(1, driver->getTexture("media\\terrain-detailmap.jpg"));

    terrain->setMaterialType(EMT_DETAIL_MAP);
    terrain->scaleTexture(20.0f, 1.0f);

    selector = smgr->createOctTreeTriangleSelector(terrain->getMesh(), terrain);
    terrain->setTriangleSelector(selector);

    ISceneNodeAnimator *anim = smgr->createCollisionResponseAnimator(selector, camera, vector3df(30, 60, 30), vector3df(0, 0, 0));
    camera->addAnimator(anim);
    anim->drop();
Collision detection doesn't work, I still can fly throught the hills and ground. Thanx for answers...
devkid
Posts: 9
Joined: Sat Jun 03, 2006 7:57 pm

Post by devkid »

Code: Select all

// create triangle selector for the terrain	
scene::ITriangleSelector* selector =
    smgr->createTerrainTriangleSelector(terrain, 0);
terrain->setTriangleSelector(selector);
selector->drop();

// create collision response animator and attach it to the camera
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
	selector, camera, core::vector3df(60,100,60),
	core::vector3df(0,0,0), 
	core::vector3df(0,50,0));
camera->addAnimator(anim);
anim->drop();
Look at the example in the tutorial.
Post Reply