My collision detection doesnt work :{

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
silli
Posts: 3
Joined: Fri Apr 10, 2009 7:18 pm

My collision detection doesnt work :{

Post by silli »

Yeah, I made simple collision detection, but it doesnt seem to work.

Ive been trying to solve this out for few hours and it's driving me nuts.

LoadMapWithCollision function:

Code: Select all

int LoadMapWithCollision(char mapfilename[100], char texturefilename[100], int mapposx, int mapposy, int mapposz, int scenenodeindex, int radiusx, int radiusy, int radiusz)
{

        mapmesh = smgr->getMesh(mapfilename);
        mapnode = 0;

        mapnode = smgr->addOctTreeSceneNode(mapmesh->getMesh(0));
        mapnode->setMaterialFlag(EMF_LIGHTING, false);
	    mapnode->setMaterialTexture(0, driver->getTexture(texturefilename) );

        mapnode->setPosition(core::vector3df(mapposx,mapposy,mapposz));

        selector = smgr->createOctTreeTriangleSelector(mapmesh->getMesh(0), mapnode, 128);
        mapnode->setTriangleSelector(selector);

        anim = smgr->createCollisionResponseAnimator(selector, anim_node[scenenodeindex], core::vector3df(radiusx,radiusy,radiusz),core::vector3df(0,0,0),core::vector3df(0,50,0));
        anim_node[scenenodeindex]->addAnimator(anim);
        anim->drop();

}
And how I call it on main() before while loop:

LoadMapWithCollision("testmodel.ms3d", "texture.bmp", -100, 0, 0, ptr, 30,50,30);

ptr is index of my IAnimatedMeshSceneNode array.

So basically Im trying to load model, and make another model to collide with it (zombie02.ms3d model with texture 'zombie.jpg')

testmodel.ms3d loads fine with texture, and the other model (which should collide with testmodel) is loaded too.

Somehow they dont however collide.

Cmd line says following:

Irrlicht Engine version 1.5
Microsoft Windows Vista Personal Service Pack 1 (Build 6001)
Using renderer: OpenGL 2.1.2
GeForce 9800 GTX/9800 GTX+/PCI/SSE2: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
GLSL version: 1.3
Loaded texture: C:\Users\veepee\Desktop\Cottage\Zombie.jpg
Loaded mesh: zombie02.ms3d
Loaded mesh: testmodel.ms3d
Needed 0ms to create OctTree SceneNode.(13 nodes, 938 polys)
Loaded texture: C:\Users\veepee\Desktop\Cottage\texture.bmp
Needed 0ms to create OctTreeTriangleSelector.(9 nodes, 938 polys)

Everything appears to be fine, no errors or anything. Both models show up, but they just dont collide. :oops:

EDIT. Could this problem be related to the radius?

Is the radius, the collision radius from "map" or "object which collides to the map"?

As my map is huge, if it's map's collision radius, Id have to set the radius huge.

If the radius is my object's radius, it would be small since my object model is small.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

first if you create a selector, then drop it later

Code: Select all

selector = smgr->createOctTreeTriangleSelector(mapmesh->getMesh(0), mapnode, 128);
        mapnode->setTriangleSelector(selector); 
selector->drop();
then, whats anim_node? you want that to collide with your map?
it seems like you just make collision with just one node and the map.
i think you should add the animator to every moving node.

then the last, radius is for the moving node, so the little one
Image
Image
silli
Posts: 3
Joined: Fri Apr 10, 2009 7:18 pm

Post by silli »

B@z wrote:first if you create a selector, then drop it later

Code: Select all

selector = smgr->createOctTreeTriangleSelector(mapmesh->getMesh(0), mapnode, 128);
        mapnode->setTriangleSelector(selector); 
selector->drop();
I tried that, but it doesnt work either.
then, whats anim_node? you want that to collide with your map?

Its node of my models, a single animated scene node. Yes, I want collide that with my map.
it seems like you just make collision with just one node and the map.
i think you should add the animator to every moving node.
True, Im testing it with only one node first.


At this moment, zombie (the node) seems to collide my tower (world), but only at some parts of tower (in the middle). In the bottom of the tower I can still walk throught.

So this isnt radius related problem either?

What could cause this?
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

coz you just give the towers selector for the zombie.
i dont see where you add the other objects to the collision array.

you have to use a meta triangle selector, put into it the world, and all the objects what you want your model to collide (world + static objects)

that selector dropping thingy has nothing to do with your current problem but you MUST do that xD

or you just have one static node (world) and one moving node?

if thats the case i dunno why can you walk through. what do u pass for the radiusx,y,z?
Image
Image
lokiare
Posts: 40
Joined: Wed Feb 04, 2009 5:40 pm

Post by lokiare »

First you have to understand how the collision detection works. In this case it is a direct triangle collision test. The problem lies in that the only objects you should test for collision are the ones that move, so what you need to do is create a meta selector (its just a selector that holds all the different triangle selectors). Then you add each object that you want to collide with like all static buildings and rocks and the world's triangle selectors. Then instead of creating a world based collision animator you create an animator for each object that is moving. This is the key, you are creating a collision response animator for the map instead of for the moving objects in the map. Once you change this around and pass the meta selector to the collision response animators it should work fine. Also you can get the radius of an node by calling its get bounding box function and asking it for the extent of the bounding box. This makes it easy to add a bunch of nodes in a loop.
Post Reply